Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
refactor terminal, xterm; +keycodes, mouse support
Browse files Browse the repository at this point in the history
- Refactor Terminal Class.
    - Add terminal support for Control+Alt+Key & Shift+Alt+Key sequences.
    - Modularize the Byte reading loop. Make structure simpler and clearer.
    - Move key-code structures to keyCodes Class.
    - Show relevant info when catching error related to issue #1.
    - Add initial mouse support.
    - Temporarily made public some properties and methods for easy interop.
- Rename ANSI class to XTerm.
- Rename ansi.dart file to xterm_control.dart
- Add keyCodes Class in xterm_keycodes.dart.
- Rename CLI --terminal-type ansi argument to xterm.
- New word: KEY
- Modify InputQueue & VirtualMachine classes.
    - Implemented a single character input buffer for the word KEY
    - Rename VirtualMachine.source property to input.
    - Rename InputQueue properties: id to sourceId & length to sourceLength.
    - Rename getLineFromSimpleTerminal() to getLineFromXTerm().
    - Enable XTerm by default only in Linux and MacOs
- ForthError.unmanaged() text update. Update error tests.
- Minor fixes.
- More comments.
- Update readme.
  • Loading branch information
joseluis committed Mar 10, 2016
1 parent f4484e6 commit ca4860f
Show file tree
Hide file tree
Showing 15 changed files with 735 additions and 372 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ You'll first need to install the appropriate version of [Dart](https://www.dartl
pub global activate --source path ./
```

*Read more about [pub global](https://www.dartlang.org/tools/pub/cmd/pub-global.html) & [script snapshots](https://www.dartlang.org/articles/snapshots/#how-to-generate-and-use-script-snapshots).*

### Command Line Interface

**Usage Examples**
Expand Down
6 changes: 3 additions & 3 deletions bin/common/forandar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void argParser(List<String> args, Configuration c, InputQueue i) {
allowMultiple: false,
valueHelp: 'LINES',
callback: _checkArgIsPositiveInteger,
help: "Specify the history lines in 'ansi' ${_defaultValue(Configuration.defaultTerminalHistoryLines)}"
help: "Specify the history lines in 'xterm' ${_defaultValue(Configuration.defaultTerminalHistoryLines)}"
)

..addSeparator('Misc options:') // ---
Expand Down Expand Up @@ -208,8 +208,8 @@ void argParser(List<String> args, Configuration c, InputQueue i) {
case 'simple':
c.setOption('terminalType', TerminalType.simple);
break;
case 'ansi':
c.setOption('terminalType', TerminalType.ansi);
case 'xterm':
c.setOption('terminalType', TerminalType.xterm);
break;
}
} catch(e) {
Expand Down
87 changes: 0 additions & 87 deletions lib/src/cli/ansi.dart

This file was deleted.

25 changes: 23 additions & 2 deletions lib/src/cli/common/primitives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ part of forandar.cli.primitives;
///
void includeWordsCli(VirtualMachine vm, Dictionary d) {
includeWordsCliStandardCore(vm, d);
includeWordsCliStandardOptionalFacility(vm, d);
includeWordsCliStandardOptionalFile(vm, d);
includeWordsCliStandardOptionalProgrammingTools(vm, d);
includeWordsCliStandardOptionalTools(vm, d);
includeWordsCliNotStandardExtra(vm, d);
}

Expand All @@ -21,6 +22,21 @@ void includeWordsCliStandardCore(VirtualMachine vm, Dictionary d) {
stdout.write("${vm.dataStack.pop} ");
});

/// Receive one character char.
///
/// [KEY][link] ( -- char )
/// [link]: https://forth-standard.org/standard/core/KEY
d.addWordOver("KEY", () {
vm.dataStack.push(stdin.readByteSync());

if (vm.input.keyBuffer >= 0) {
vm.dataStack.push(vm.input.keyBuffer);
vm.source.keyBuffer = -1;
} else {
vm.dataStack.push(stdin.readByteSync());
}
});

/// Display one space.
///
/// [SPACE][link] ( -- )
Expand Down Expand Up @@ -53,6 +69,10 @@ void includeWordsCliStandardCore(VirtualMachine vm, Dictionary d) {
});
}

/// [The optional Facility word set][http://forth-standard.org/standard/facility]
void includeWordsCliStandardOptionalFacility(VirtualMachine vm, Dictionary d) {
}

/// [The optional File-Access word set][http://forth-standard.org/standard/file]
void includeWordsCliStandardOptionalFile(VirtualMachine vm, Dictionary d) {

Expand All @@ -63,7 +83,8 @@ void includeWordsCliStandardOptionalFile(VirtualMachine vm, Dictionary d) {
//d.addWordOver("INCLUDED", () {}); // TODO
}

void includeWordsCliStandardOptionalProgrammingTools(VirtualMachine vm, Dictionary d) {
/// [The optional Programming-Tools word set][http://forth-standard.org/standard/tools]
void includeWordsCliStandardOptionalTools(VirtualMachine vm, Dictionary d) {

// ? BYE

Expand Down
15 changes: 7 additions & 8 deletions lib/src/cli/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:forandar/src/core/input.dart';
import 'package:forandar/src/core/globals.dart';

// Cli
import 'package:forandar/src/cli/ansi.dart';
import 'package:forandar/src/cli/terminal.dart';

// The input queue adapted for the CLI interface.
Expand All @@ -27,14 +26,14 @@ class InputQueue extends InputQueueBase {
// Be the most compatible by default.
if (globalConfig.getOption('terminalType') == TerminalType.auto) {

if (Platform.isWindows) {
return await readLineFromSimpleTerminal();
if (Platform.isLinux || Platform.isMacOS) {
return await readLineFromXTerm();
} else {
return await readLineFromAnsiTerminal();
return await readLineFromSimpleTerminal();
}

} else if (globalConfig.getOption('terminalType') == TerminalType.ansi) {
return await readLineFromAnsiTerminal();
} else if (globalConfig.getOption('terminalType') == TerminalType.xterm) {
return await readLineFromXTerm();
} else {
return await readLineFromSimpleTerminal();
}
Expand All @@ -45,8 +44,8 @@ class InputQueue extends InputQueueBase {
return await stdin.readLineSync();
}

// An ANSI full-featured terminal, with extra functionality.
Future<String> readLineFromAnsiTerminal() async {
// An XTerm compatible full-featured terminal, with extra functionality.
Future<String> readLineFromXTerm() async {
return await Terminal.readLineSync(); // works, but problem is UTF8
}
}
Loading

0 comments on commit ca4860f

Please sign in to comment.