Skip to content

Commit

Permalink
Implemented Graphics Character Set. Fixes p-e-w#358 and p-e-w#413
Browse files Browse the repository at this point in the history
  • Loading branch information
RedHatter committed Nov 6, 2015
1 parent 2abaa56 commit d4199b8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/CharacterAttributes.vala
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ public class CharacterAttributes : Object {
color1 = color_scheme.get_foreground_color(dark);
} else {
color1 = color_scheme.get_indexed_color(foreground_color, dark);
if (bold) {
color1.red = (color1.red + 0.1).clamp(0.0, 1.0);
color1.green = (color1.green + 0.1).clamp(0.0, 1.0);
color1.blue = (color1.blue + 0.1).clamp(0.0, 1.0);
}

}
}

Expand Down
58 changes: 57 additions & 1 deletion src/TerminalOutput.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,48 @@ public class TerminalOutput : Gee.ArrayList<OutputLine> {
// not its position on the screen
public CursorPosition cursor_position = CursorPosition();

// Character Sets
private Gee.Map<unichar,unichar> graphics_set = new Gee.HashMap<unichar, unichar>();
private Gee.Map<unichar,unichar> default_set = new Gee.HashMap<unichar, unichar>();

private Gee.Map<unichar,unichar> active_character_set;
private void load_character_sets() {
graphics_set['`'] = 0x2666;
graphics_set['a'] = 0x1F67E;
graphics_set['b'] = 0x0009;
graphics_set['c'] = 0x000C;
graphics_set['d'] = 0x000D;
graphics_set['e'] = 0x000A;
graphics_set['f'] = 0x2218;
// graphics_set['g'] = ;
// graphics_set['h'] = ;
graphics_set['i'] = 0x000B;
graphics_set['j'] = 0x2518;
graphics_set['k'] = 0x2510;
graphics_set['l'] = 0x250C;
graphics_set['m'] = 0x2514;
graphics_set['n'] = 0x253B;
graphics_set['o'] = 0x23BA;
graphics_set['p'] = 0x23BB;
graphics_set['q'] = 0x2500;
graphics_set['r'] = 0x23BC;
graphics_set['s'] = 0x23BD;
graphics_set['t'] = 0x251C;
graphics_set['u'] = 0x2524;
graphics_set['v'] = 0x2533;
graphics_set['w'] = 0x252B;
graphics_set['x'] = 0x2502;
graphics_set['y'] = 0x2A7D;
graphics_set['z'] = 0x2A7E;
graphics_set['{'] = 0x03C0;
graphics_set['|'] = 0x2260;
graphics_set['}'] = 0x2265;
graphics_set['~'] = 0x22C5;

active_character_set = default_set;
}


public struct CursorPosition {
public int line;
public int column;
Expand All @@ -77,6 +119,7 @@ public class TerminalOutput : Gee.ArrayList<OutputLine> {
public CursorPosition command_start_position;

public TerminalOutput(Terminal terminal) {
load_character_sets();
this.terminal = terminal;

// Default attributes
Expand Down Expand Up @@ -357,6 +400,14 @@ public class TerminalOutput : Gee.ArrayList<OutputLine> {

case TerminalStream.StreamElement.ControlSequenceType.DESIGNATE_G0_CHARACTER_SET_VT100:
// The program "top" emits this sequence repeatedly
switch (stream_element.text[stream_element.text.length-1]) {
case 'B':
active_character_set = default_set;
break;
case '0':
active_character_set = graphics_set;
break;
}
//print_interpretation_status(stream_element, InterpretationStatus.UNSUPPORTED);
break;

Expand Down Expand Up @@ -563,7 +614,12 @@ public class TerminalOutput : Gee.ArrayList<OutputLine> {
}

private void print_text(string text) {
var text_element = new TextElement(text, current_attributes);
var translated = "";
// foreach(char c in text.data)
for(var i = 0; i < text.length; i++)
translated += active_character_set.has_key(text[i]) ? active_character_set[text[i]].to_string () : text[i].to_string ();

var text_element = new TextElement(translated, current_attributes);
get(cursor_position.line).insert_element(text_element, cursor_position.column, true);
// TODO: Handle double-width unicode characters and tabs
move_cursor(cursor_position.line, cursor_position.column + text_element.get_length());
Expand Down

0 comments on commit d4199b8

Please sign in to comment.