]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/gui/cli/JubCLIChatUI.m
Add line editing support to the CLI UI
[jubjub.git] / src / gui / cli / JubCLIChatUI.m
index 5803ba75589c0ca95cc383cbf15164ea495b944f..19e3629c87f21c4d1b42005724cf5019023495a9 100644 (file)
@@ -1,6 +1,8 @@
 #import "JubCLIChatUI.h"
 #import "JubCLIColor.h"
 
+#import "linenoise.h"
+
 @implementation JubCLIChatUI
 - initWithTitle: (OFString*)title
      closeBlock: (jub_close_block_t)closeBlock
@@ -10,6 +12,7 @@
 
        @try {
                _sendBlock = [sendBlock copy];
+               _title = [title copy];
        } @catch (id e) {
                [self release];
                @throw e;
 - (void)dealloc
 {
        [_sendBlock release];
+       [_title release];
        [super dealloc];
 }
 
 - (void)addMessage: (OFString*)text
            sender: (OFString*)sender
 {
-       [of_stdout writeFormat: BOLD("%@:") @" %@\n", sender, text];
+       [of_stdout writeString: @"\r" COL_IN(@"-> ")];
+       [of_stdout writeFormat: BOLD(@"%@:") @" %@\n", sender, text];
+       [[Linenoise sharedLinenoise] refreshLine];
 }
 
 - (void)send: (OFString*)text
 {
+       [of_stdout writeString: @"\033[1A" COL_OUT(@"<- ")];
+       [of_stdout writeFormat: BOLD(@"%@:") @" %@\n", _title, text];
+
        _sendBlock(text);
 }
 @end