Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: tools/ddbg/lib/terminfo.dart

Issue 69343017: Add support for command-line editing to ddbg. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tools/ddbg/bin/ddbg.dart ('K') | « tools/ddbg/lib/commando.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/ddbg/lib/terminfo.dart
===================================================================
--- tools/ddbg/lib/terminfo.dart (revision 0)
+++ tools/ddbg/lib/terminfo.dart (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// 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.
+ final String cursorBack = _tputGetSequence('cub1');
+
+ // Forward one character.
+ final String cursorForward = _tputGetSequence('cuf1');
+
+ // Up one character.
+ final String cursorUp = _tputGetSequence('cuu1');
+
+ // Down one character.
+ final String cursorDown = _tputGetSequence('cud1');
+
+ // Clear to end of line.
+ final String clrEOL = _tputGetSequence('el');
+
+ // Clear screen and home cursor.
+ final String clear = _tputGetSequence('clear');
+
+ // Left arrow keypress
+ final String keyLeftArrow = _tputGetSequence('kcub1');
+}
« tools/ddbg/bin/ddbg.dart ('K') | « tools/ddbg/lib/commando.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698