Chromium Code Reviews| Index: tools/ddbg/lib/terminfo.dart |
| =================================================================== |
| --- tools/ddbg/lib/terminfo.dart (revision 0) |
| +++ tools/ddbg/lib/terminfo.dart (revision 0) |
| @@ -0,0 +1,63 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
hausner
2013/11/21 16:12:03
2013
turnidge
2013/11/21 18:25:11
Done.
|
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:convert'; |
| +import 'dart:io'; |
| + |
| +int _tputGetInteger(String capName) { |
| + var result = Process.runSync('tput', ['$capName'], stdoutEncoding:UTF8); |
| + if (result.exitCode != 0) { |
| + return 0; |
| + } |
| + return int.parse(result.stdout); |
| +} |
| + |
| +String _tputGetSequence(String capName) { |
| + var result = Process.runSync('tput', ['$capName'], stdoutEncoding:UTF8); |
| + if (result.exitCode != 0) { |
| + return ''; |
| + } |
| + return result.stdout; |
| +} |
| + |
| +class TermInfo { |
| + TermInfo() { |
| + resize(); |
| + } |
| + |
| + int get lines => _lines; |
| + int get cols => _cols; |
| + |
| + int _lines; |
| + int _cols; |
| + |
| + void resize() { |
| + _lines = _tputGetInteger('lines'); |
| + _cols = _tputGetInteger('cols'); |
| + } |
| + |
| + // Back one character. |
| + String cursorBack = _tputGetSequence('cub1'); |
|
hausner
2013/11/21 16:12:03
Any reason why you make lines and cols a readonly
turnidge
2013/11/21 18:25:11
Done.
|
| + |
| + // Forward one character. |
| + String cursorForward = _tputGetSequence('cuf1'); |
| + |
| + // Up one character. |
| + String cursorUp = _tputGetSequence('cuu1'); |
| + |
| + // Down one character. |
| + String cursorDown = _tputGetSequence('cud1'); |
| + |
| + // Clear to end of line. |
| + String clrEOL = _tputGetSequence('el'); |
| + |
| + // Clear screen and home cursor. |
| + String clear = _tputGetSequence('clear'); |
| + |
| + // Left arrow keypress |
| + String keyLeftArrow = _tputGetSequence('kcub1'); |
| + |
| + String enterAmMode = _tputGetSequence('smam'); |
| + String exitAmMode = _tputGetSequence('rmam'); |
| +} |