Permalink
Browse files

Add it2universion. Add labels to push and pop for unicode version.

  • Loading branch information...
1 parent 9ad0bc0 commit 4dea9ca61b622213949aaef2ace50c841344974b @gnachman committed Jan 2, 2017
Showing with 139 additions and 13 deletions.
  1. +35 −13 sources/VT100Terminal.m
  2. +104 −0 tests/it2universion.sh
@@ -2169,10 +2169,10 @@ - (void)executeXtermSetKvp:(VT100Token *)token {
[delegate_ terminalSendReport:[s dataUsingEncoding:NSUTF8StringEncoding]];
}
} else if ([key isEqualToString:@"UnicodeVersion"]) {
- if ([value isEqualToString:@"push"]) {
- [self pushUnicodeVersion];
- } else if ([value isEqualToString:@"pop"]) {
- [self popUnicodeVersion];
+ if ([value hasPrefix:@"push"]) {
+ [self pushUnicodeVersion:value];
+ } else if ([value hasPrefix:@"pop"]) {
+ [self popUnicodeVersion:value];
} else if ([value isNumeric]) {
[delegate_ terminalSetUnicodeVersion:[value integerValue]];
}
@@ -2398,19 +2398,41 @@ - (void)executeFinalTermToken:(VT100Token *)token {
}
}
-- (void)pushUnicodeVersion {
- [_unicodeVersionStack addObject:@([delegate_ terminalUnicodeVersion])];
+- (NSString *)substringAfterSpaceInString:(NSString *)string {
+ NSInteger i = [string rangeOfString:@" "].location;
+ if (i == NSNotFound) {
+ return nil;
+ } else {
+ return [string substringFromIndex:i + 1];
+ }
}
-- (void)popUnicodeVersion {
- if (_unicodeVersionStack.count == 0) {
- return;
- }
- NSNumber *value = [_unicodeVersionStack lastObject];
- [_unicodeVersionStack removeLastObject];
- [delegate_ terminalSetUnicodeVersion:value.integerValue];
+- (void)pushUnicodeVersion:(NSString *)label {
+ label = [self substringAfterSpaceInString:label];
+ [_unicodeVersionStack addObject:@[ label ?: @"", @([delegate_ terminalUnicodeVersion]) ]];
}
+- (void)popUnicodeVersion:(NSString *)label {
+ label = [self substringAfterSpaceInString:label];
+ while (_unicodeVersionStack.count > 0) {
+ id entry = [[[_unicodeVersionStack lastObject] retain] autorelease];
+ [_unicodeVersionStack removeLastObject];
+
+ NSNumber *value = nil;
+ NSString *entryLabel = nil;
+ if ([entry isKindOfClass:[NSNumber class]]) {
+ // A restored value might have just a number. New values are always an array.
+ value = entry;
+ } else {
+ entryLabel = [entry objectAtIndex:0];
+ value = [entry objectAtIndex:1];
+ }
+ if (label.length == 0 || [label isEqualToString:entryLabel]) {
+ [delegate_ terminalSetUnicodeVersion:value.integerValue];
+ return;
+ }
+ }
+}
- (NSDictionary *)dictionaryForGraphicRendition:(VT100GraphicRendition)graphicRendition {
return @{ kGraphicRenditionBoldKey: @(graphicRendition.bold),
View
@@ -0,0 +1,104 @@
+#!/bin/bash
+
+# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
+# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
+# only accepts ESC backslash for ST.
+function print_osc() {
+ if [[ $TERM == screen* ]] ; then
+ printf "\033Ptmux;\033\033]"
+ else
+ printf "\033]"
+ fi
+}
+
+# More of the tmux workaround described above.
+function print_st() {
+ if [[ $TERM == screen* ]] ; then
+ printf "\a\033\\"
+ else
+ printf "\a"
+ fi
+}
+
+function show_help() {
+ echo "Usage:" 1>& 2
+ echo " $(basename $0) set 8" 1>& 2
+ echo " $(basename $0) set 9" 1>& 2
+ echo " $(basename $0) push [name]" 1>& 2
+ echo " Saves the current version with an optional name." 1>& 2
+ echo " $(basename $0) pop [name]" 1>& 2
+ echo " If name is given, all versions up to and including the one with the matching name are popped." 1>& 2
+}
+
+function set_version() {
+ print_osc
+ printf "1337;UnicodeVersion=$1"
+ print_st
+}
+
+function push_version() {
+ print_osc
+ printf "1337;UnicodeVersion=push $1"
+ print_st
+}
+
+function pop_version() {
+ print_osc
+ printf "1337;UnicodeVersion=pop $1"
+ print_st
+}
+
+## Main
+if [[ $# == 0 ]]
+then
+ show_help
+ exit 1
+fi
+
+if [[ $1 == set ]]
+then
+ if [[ $# != 2 ]]
+ then
+ show_help
+ exit 1
+ fi
+ set_version $2
+elif [[ $1 == push ]]
+then
+ if [[ $# == 1 ]]
+ then
+ push_version ""
+ elif [[ $# == 2 ]]
+ then
+ if [[ $2 == "" ]]
+ then
+ echo "Name must not be empty" 1>& 2
+ exit 1
+ fi
+ push_version "$2"
+ else
+ show_help
+ exit 1
+ fi
+elif [[ $1 == pop ]]
+then
+ if [[ $# == 1 ]]
+ then
+ pop_version ""
+ elif [[ $# == 2 ]]
+ then
+ if [[ $2 == "" ]]
+ then
+ echo "Name must not be empty" 1>& 2
+ exit 1
+ fi
+ pop_version "$2"
+ else
+ show_help
+ exit 1
+ fi
+else
+ show_help
+ exit 1
+fi
+

0 comments on commit 4dea9ca

Please sign in to comment.