or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast-browser.mdconsole-application.mdindex.mdobject-inspector.mdsystem-integration.mdtext-editing.md

console-application.mddocs/

0

# Console Application

1

2

The main Console class provides an interactive Groovy development environment with script execution, file management, debugging tools, and comprehensive IDE-like features.

3

4

## Core Console Class

5

6

```groovy { .api }

7

class Console implements CaretListener, HyperlinkListener, ComponentListener, FocusListener {

8

// Constructors

9

Console()

10

Console(Binding binding)

11

Console(ClassLoader parent, Binding binding, CompilerConfiguration baseConfig)

12

13

// Application Entry Points

14

static void main(String[] args)

15

void run()

16

void run(Map defaults)

17

void run(JApplet applet) // @Deprecated

18

19

// Script Execution

20

void runScript(EventObject evt = null)

21

void runSelectedScript(EventObject evt = null)

22

void compileScript(EventObject evt = null)

23

24

// File Operations

25

void fileNewFile(EventObject evt = null)

26

void fileNewWindow(EventObject evt = null)

27

void fileOpen(EventObject evt = null)

28

void loadScriptFile(File file)

29

30

// Development Tools

31

void inspectLast(EventObject evt = null)

32

void inspectVariables(EventObject evt = null)

33

void inspectAst(EventObject evt = null)

34

void inspectCst(EventObject evt = null)

35

void inspectTokens(EventObject evt = null)

36

37

// UI Management

38

void clearOutput(EventObject evt = null)

39

void showAbout(EventObject evt = null)

40

void preferences(EventObject evt = null)

41

42

// Public Fields

43

static URL ICON_PATH

44

static URL NODE_ICON_PATH

45

}

46

```

47

48

### Parameters

49

50

**Constructor Parameters:**

51

- `binding` (Binding, optional): Variable binding context for script execution. Defaults to new Binding()

52

- `parent` (ClassLoader, optional): Parent class loader for script compilation

53

- `baseConfig` (CompilerConfiguration, optional): Base compiler configuration. Defaults to new CompilerConfiguration()

54

55

**run() Method Parameters:**

56

- `defaults` (Map, optional): Configuration map with UI defaults like title, size, etc.

57

- `applet` (JApplet, optional): Parent applet when running as applet

58

59

### Returns

60

61

- **main()**: void - Launches the console application

62

- **run()**: void - Starts the console UI

63

- Other methods return void and are typically called by UI event handlers

64

65

## Applet Support

66

67

```groovy { .api }

68

class ConsoleApplet extends JApplet {

69

// Constructor

70

ConsoleApplet()

71

72

// Applet Lifecycle Methods

73

void init()

74

void start()

75

void stop()

76

void destroy()

77

78

// Console Integration

79

Console getConsole()

80

}

81

```

82

83

The ConsoleApplet class provides applet-compatible console functionality for web browser integration. It wraps the main Console functionality in an applet container for deployment in web browsers.

84

85

**Note:** Applet support is deprecated as modern browsers no longer support Java applets.

86

87

## Legacy API (Deprecated)

88

89

**Warning:** The `groovy.ui` package is deprecated. Use `groovy.console.ui` for new code.

90

91

```groovy { .api }

92

// Legacy imports (same API as groovy.console.ui but deprecated)

93

import groovy.ui.Console // @Deprecated

94

import groovy.ui.ConsoleApplet // @Deprecated

95

```

96

97

## Usage Examples

98

99

### Basic Console Launch

100

101

```groovy

102

// Launch console with default settings

103

groovy.console.ui.Console.main([] as String[])

104

105

// Or programmatically

106

def console = new groovy.console.ui.Console()

107

console.run()

108

```

109

110

### Custom Console Configuration

111

112

```groovy

113

// With custom binding

114

def binding = new Binding()

115

binding.setVariable('name', 'World')

116

binding.setVariable('data', [1, 2, 3, 4, 5])

117

118

def console = new groovy.console.ui.Console(binding)

119

console.run([

120

title: 'My Groovy Console',

121

size: [800, 600]

122

])

123

```

124

125

### Programmatic Script Loading

126

127

```groovy

128

def console = new groovy.console.ui.Console()

129

console.loadScriptFile(new File('my-script.groovy'))

130

console.run()

131

```

132

133

### With Custom ClassLoader

134

135

```groovy

136

def customClassLoader = new GroovyClassLoader()

137

def binding = new Binding()

138

def config = new CompilerConfiguration()

139

140

def console = new groovy.console.ui.Console(customClassLoader, binding, config)

141

console.run()

142

```

143

144

## Integration Points

145

146

### File Type Associations

147

148

The console includes built-in file filtering for Groovy scripts:

149

150

```groovy

151

// Internal file filter for .groovy files

152

class GroovyFileFilter extends FileFilter {

153

// Filters for *.groovy files in file dialogs

154

}

155

```

156

157

### Event Handling

158

159

The Console implements multiple listener interfaces for comprehensive UI interaction:

160

- `CaretListener` - Text cursor position changes

161

- `HyperlinkListener` - Hyperlink navigation in output

162

- `ComponentListener` - Window resizing and positioning

163

- `FocusListener` - Focus gain/loss events

164

165

### Execution Context

166

167

Scripts executed in the console have access to:

168

- Binding variables set during construction

169

- Console instance itself (for advanced integration)

170

- Full Groovy runtime and standard library

171

- Any additional dependencies in the classpath