Java Code Examples for org.aesh.terminal.utils.Config#isOSPOSIXCompatible()
The following examples show how to use
org.aesh.terminal.utils.Config#isOSPOSIXCompatible() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyMapperTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testQuoteMapKeys() { if(Config.isOSPOSIXCompatible()) { EditModeBuilder builder = EditModeBuilder.builder(); InputrcParser.parseLine("\"\\M-a\": meta", builder); assertEquals(builder.create().parse(Key.META_a).name(), new NoAction().name()); InputrcParser.parseLine("\"\\M-[D\": backward-char", builder); assertEquals(builder.create().parse(Key.LEFT).name(), new BackwardChar().name()); InputrcParser.parseLine("\"\\M-[C\": forward-char", builder); assertEquals(builder.create().parse(Key.RIGHT).name(), new ForwardChar().name()); InputrcParser.parseLine("\"\\M-[A\": previous-history", builder); assertEquals(builder.create().parse(Key.UP).name(), new PrevHistory().name()); InputrcParser.parseLine("\"\\M-[B\": next-history", builder); assertEquals(builder.create().parse(Key.DOWN).name(), new NextHistory().name()); InputrcParser.parseLine("\"\\M-\\C-D\": backward-char", builder); assertEquals(builder.create().parse(Key.META_CTRL_D).name(), new BackwardChar().name()); InputrcParser.parseLine("\"\\C-\\M-d\": backward-char", builder); assertEquals(builder.create().parse(Key.META_CTRL_D).name(), new BackwardChar().name()); InputrcParser.parseLine("\"\\C-a\": end-of-line", builder); assertEquals(builder.create().parse(Key.CTRL_A).name(), new EndOfLine().name()); } }
Example 2
Source File: DeviceBuilder.java From aesh-readline with Apache License 2.0 | 6 votes |
public TerminalDevice build() { if(name == null) name = Config.isOSPOSIXCompatible() ? "ansi" : "windows"; String data = getCapabilityFromType(); TerminalDevice device = new TerminalDevice(name); if(data != null) { Set<Capability> bools = new HashSet<>(); Map<Capability, Integer> ints = new HashMap<>(); Map<Capability, String> strings = new HashMap<>(); InfoCmp.parseInfoCmp(data, bools,ints, strings); device.addAllCapabilityBooleans(bools); device.addAllCapabilityInts(ints); device.addAllCapabilityStrings(strings); } return device; }
Example 3
Source File: InputrcParser.java From aesh-readline with Apache License 2.0 | 6 votes |
protected static void parseLine(String line, EditModeBuilder editMode) { Matcher variableMatcher = variablePattern.matcher(line); if (variableMatcher.matches()) { Variable variable = Variable.findVariable(variableMatcher.group(1)); if(variable != null) parseVariables(variable, variableMatcher.group(2), editMode); } //TODO: currently the inputrc parser is posix only else if (Config.isOSPOSIXCompatible()) { Matcher keyQuoteMatcher = keyQuoteNamePattern.matcher(line); if(keyQuoteMatcher.matches()) { editMode.addAction(mapQuoteKeys(keyQuoteMatcher.group(1)), keyQuoteMatcher.group(3)); } else { Matcher keyMatcher = keyNamePattern.matcher(line); if(keyMatcher.matches()) { editMode.addAction(mapKeys(keyMatcher.group(1)), keyMatcher.group(3)); } } } }
Example 4
Source File: KeyTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testFindStartKeyPosition() { int[] input = new int[]{2, 27, 65}; Key inc = Key.findStartKey(input, 0); assertEquals(Key.CTRL_B, inc); inc = Key.findStartKey(input, 1); assertEquals(Key.ESC, inc); System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length); inc = Key.findStartKey(input, 2); assertEquals(Key.A, inc); if (Config.isOSPOSIXCompatible()) { input = new int[]{32, 27, 91, 65, 10}; inc = Key.findStartKey(input, 0); assertEquals(Key.SPACE, inc); inc = Key.findStartKey(input, 1); assertEquals(Key.UP, inc); inc = Key.findStartKey(input, 4); assertEquals(Key.ENTER, inc); input = new int[]{10}; inc = Key.findStartKey(input, 0); assertEquals(Key.ENTER, inc); } }
Example 5
Source File: KeyTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testFindStartKey() { int[] input = new int[]{2, 27, 65}; Key inc = Key.findStartKey(input); assertEquals(Key.CTRL_B, inc); System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length); inc = Key.findStartKey(input); assertEquals(Key.ESC, inc); System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length); inc = Key.findStartKey(input); assertEquals(Key.A, inc); if (Config.isOSPOSIXCompatible()) { input = new int[]{32, 27, 91, 65, 10}; inc = Key.findStartKey(input); assertEquals(Key.SPACE, inc); System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length); inc = Key.findStartKey(input); assertEquals(Key.UP, inc); System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length); inc = Key.findStartKey(input); assertEquals(Key.ENTER, inc); System.arraycopy(input, inc.getKeyValues().length, input, 0, input.length - inc.getKeyValues().length); } }
Example 6
Source File: AeshConsoleBuffer.java From aesh-readline with Apache License 2.0 | 6 votes |
@Override public void clear(boolean includeBuffer) { //(windows fix) if(!Config.isOSPOSIXCompatible()) connection.stdoutHandler().accept(Config.CR); //first clear console connection.stdoutHandler().accept(ANSI.CLEAR_SCREEN); int cursorPosition = -1; if(buffer.cursor() < buffer.length()) { cursorPosition = buffer.cursor(); buffer.move(connection.stdoutHandler(), buffer.length() - cursorPosition, size().getWidth()); } //move cursor to correct position connection.stdoutHandler().accept(new int[] {27, '[', '1', ';', '1', 'H'}); //then write prompt if(!includeBuffer) buffer().reset(); //redraw drawLineForceDisplay(); if(cursorPosition > -1) buffer.move(connection.stdoutHandler(), cursorPosition-buffer.length(), size().getWidth()); }
Example 7
Source File: ExecPtyTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testParseAttributesUbuntu() throws IOException { if(Config.isOSPOSIXCompatible()) { Attributes attributes = ExecPty.doGetAttr(ubuntuSttySample); checkAttributestUbuntu(attributes); } }
Example 8
Source File: InputrcParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testParseInputrc2() throws IOException { if(Config.isOSPOSIXCompatible()) { //TODO: must fix this for windows EditMode editMode = EditModeBuilder.builder().create(); ActionDecoder actionQueue = new ActionDecoder(); actionQueue.add(new int[]{27, 91, 68}); Assert.assertEquals("backward-char", editMode.parse( actionQueue.next()).name()); actionQueue.add(new int[]{27, 91, 66}); Assert.assertEquals("next-history", editMode.parse( actionQueue.next()).name()); actionQueue.add(1); Assert.assertEquals("beginning-of-line", editMode.parse( actionQueue.next()).name()); editMode = InputrcParser.parseInputrc( new FileInputStream( Config.isOSPOSIXCompatible() ? new File("src/test/resources/inputrc2") : new File("src\\test\\resources\\inputrc2"))); actionQueue.add(new int[]{27, 91, 68}); Assert.assertEquals("forward-char", editMode.parse( actionQueue.next()).name()); actionQueue.add(new int[]{27, 91, 66}); Assert.assertEquals("previous-history", editMode.parse(actionQueue.next()).name()); actionQueue.add(new int[]{27,10}); Assert.assertEquals("backward-char", editMode.parse(actionQueue.next()).name()); actionQueue.add(1); Assert.assertEquals("forward-word", editMode.parse(actionQueue.next()).name()); } }
Example 9
Source File: KeyTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testIsPrintable() { assertTrue(Key.a.isPrintable()); assertTrue(Key.P.isPrintable()); assertTrue(Key.RIGHT_CURLY_BRACKET.isPrintable()); assertFalse(Key.BACKSPACE.isPrintable()); assertTrue(Key.isPrintable(new int[]{197})); assertTrue(Key.isPrintable(new int[]{229})); if (!Config.isOSPOSIXCompatible()) assertFalse(Key.isPrintable(new int[]{Key.WINDOWS_ESC.getFirstValue()})); }
Example 10
Source File: KeyTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testOtherOperations() { EditMode editMode = EditModeBuilder.builder(EditMode.Mode.EMACS).create(); Key up = Key.UP_2; Action action = editMode.parse(up); assertEquals(action.name(), ActionMapper.mapToAction("previous-history").name()); if (Config.isOSPOSIXCompatible()) { int[] doubleUpKey = new int[6]; for (int i = 0; i < 6; i++) { if (i > 2) doubleUpKey[i] = up.getKeyValues()[i - 3]; else doubleUpKey[i] = up.getKeyValues()[i]; } ActionDecoder actionDecoder = new ActionDecoder(editMode); actionDecoder.add(doubleUpKey); action = editMode.parse(actionDecoder.next()); assertEquals(action.name(), ActionMapper.mapToAction("previous-history").name()); } }
Example 11
Source File: ExecPtyTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testParseSizeHPUX() throws IOException { if(Config.isOSPOSIXCompatible()) { String input = new String(Files.readAllBytes( Config.isOSPOSIXCompatible() ? new File("src/test/resources/ttytype_hpux.txt").toPath() : new File("src\\test\\resources\\ttytype_hpux.txt").toPath())); Size size = ExecPty.doGetHPUXSize(input); assertEquals(47, size.getHeight()); assertEquals(112, size.getWidth()); } }
Example 12
Source File: ExecPtyTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testOptimizedParseAttributesUbuntu() throws IOException { if(Config.isOSPOSIXCompatible()) { Attributes attributes = ExecPty.doGetLinuxAttr(ubuntuSttySample); checkAttributestUbuntu(attributes); } }
Example 13
Source File: ExecPtyTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testOptimizedParseAttributesLinux() throws IOException { if(Config.isOSPOSIXCompatible()) { Attributes attributes = ExecPty.doGetLinuxAttr(linuxSttySample); checkAttributestLinux(attributes); } }
Example 14
Source File: ReadlineAliasTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void alias() throws Exception { PipedOutputStream outputStream = new PipedOutputStream(); PipedInputStream pipedInputStream = new PipedInputStream(outputStream); ByteArrayOutputStream out = new ByteArrayOutputStream(); TerminalConnection connection = new TerminalConnection(Charset.defaultCharset(), pipedInputStream, out); Readline readline = new Readline(); File aliasFile = Config.isOSPOSIXCompatible() ? new File("src/test/resources/alias1") : new File("src\\test\\resources\\alias1"); AliasManager aliasManager = new AliasManager(aliasFile, false); AliasPreProcessor aliasPreProcessor = new AliasPreProcessor(aliasManager); List<Function<String, Optional<String>>> preProcessors = new ArrayList<>(); preProcessors.add(aliasPreProcessor); readline.readline(connection, new Prompt(""), s -> { //first check this assertEquals("ls -alF", s); //then call readline again, to check the next line readline.readline(connection, new Prompt(""), t -> assertEquals("grep --color=auto -l", t), null, preProcessors); } , null, preProcessors); outputStream.write(("ll"+Config.getLineSeparator()).getBytes()); outputStream.write(("grep -l"+Config.getLineSeparator()).getBytes()); outputStream.flush(); connection.openNonBlocking(); Thread.sleep(200); }
Example 15
Source File: InputrcParser.java From aesh-readline with Apache License 2.0 | 5 votes |
private static int lookupControlKey(char c) { switch (c) { case '@' : return 0; case 'a' : return 1; case 'b' : return 2; case 'c' : return 3; case 'd' : return 4; case 'e' : return 5; case 'f' : return 6; case 'g' : return 7; case 'h' : return 8; case 'i' : return 9; case 'j' : return 10; case 'k' : return 11; case 'l' : return 12; case 'm' : return 13; case 'n' : return 14; case 'o' : return 15; case 'p' : return 16; case 'q' : return 17; case 'r' : return 18; case 's' : return 19; case 't' : return 20; case 'u' : return 21; case 'v' : return 22; case 'w' : return 23; case 'x' : return 24; case 'y' : return 25; case 'z' : return 26; case '[' : return 27; case '?' : return (Config.isOSPOSIXCompatible() ? 127 : 8); } return -1; }
Example 16
Source File: InputrcParser.java From aesh-readline with Apache License 2.0 | 4 votes |
protected static EditMode parseInputrc(InputStream inputStream, EditModeBuilder editMode) { if(inputStream == null) { LOGGER.warning("input stream is null, defaulting to emacs mode"); //TODO: create default emacs edit mode return new Emacs(); } Pattern commentPattern = Pattern.compile("^#.*"); Pattern startConstructs = Pattern.compile("^\\$if"); Pattern endConstructs = Pattern.compile("^\\$endif"); Scanner scanner = new Scanner(inputStream).useDelimiter(Config.getLineSeparator()); String line; boolean constructMode = false; while (scanner.hasNext()) { line = scanner.next(); if (line.trim().length() < 1) continue; //first check if its a comment if (commentPattern.matcher(line).matches()) continue; else if (startConstructs.matcher(line).matches()) { constructMode = true; continue; } else if (endConstructs.matcher(line).matches()) { constructMode = false; continue; } if (!constructMode) { Matcher variableMatcher = variablePattern.matcher(line); if (variableMatcher.matches()) { Variable variable = Variable.findVariable(variableMatcher.group(1)); if(variable != null) parseVariables(variable, variableMatcher.group(2), editMode); } //TODO: currently the inputrc parser is posix only else if (Config.isOSPOSIXCompatible()) { Matcher keyQuoteMatcher = keyQuoteNamePattern.matcher(line); if (keyQuoteMatcher.matches()) { editMode.addAction(mapQuoteKeys(keyQuoteMatcher.group(1)), keyQuoteMatcher.group(3)); } else { Matcher keyMatcher = keyNamePattern.matcher(line); if (keyMatcher.matches()) { editMode.addAction(mapKeys(keyMatcher.group(1)), keyMatcher.group(3)); } } } } } return editMode.create(); }
Example 17
Source File: Buffer.java From aesh-readline with Apache License 2.0 | 4 votes |
private void moveCursorToStartAndPrint(Consumer<int[]> out, IntArrayBuilder builder, int width, boolean replace, boolean viMode) { if(cursor > 0 || delta < 0) { //if we replace we do a quick way of moving to the beginning if(replace) { builder.append(moveNumberOfColumns(width, 'D')); } else { int length = promptLength() + cursor; if(length > 0 && (length % width == 0)) length = width; else { length = length % width; //if not deleting backward the cursor should not move if(delta < 0 && deletingBackward) length += Math.abs(delta); } builder.append(moveNumberOfColumns(length, 'D')); } //TODO: could optimize this i think if delta > 0 it should not be needed builder.append(ANSI.ERASE_LINE_FROM_CURSOR); } if(promptLength() > 0) builder.append(prompt.getANSI()); //dont print out the line if its empty if(size > 0) { if(isMasking()) { //no output if(prompt.getMask() != '\u0000') { //only output the masked char int[] mask = new int[size]; Arrays.fill(mask, prompt.getMask()); builder.append(mask); } } else builder.append(getLine()); } //pad if we are at the end of the terminal if((size + promptLength()) % width == 0 && cursor == size) { builder.append(new int[]{32, 13}); } //make sure we sync the cursor back if(!deltaChangedAtEndOfBuffer) { if((size + promptLength()) % width == 0 && (Config.isOSPOSIXCompatible() || (Config.isWindows() && WinSysTerminal.isVTSupported()))) builder.append(syncCursor(size+promptLength()-1, cursor+promptLength(), width, true)); else builder.append(syncCursor(size+promptLength(), cursor+promptLength(), width)); } //end of buffer and vi mode else if(viMode && cursor == size) { builder.append(moveNumberOfColumns(1, 'D')); cursor--; } out.accept(builder.toArray()); isPromptDisplayed = true; }
Example 18
Source File: KeyMapperTest.java From aesh-readline with Apache License 2.0 | 4 votes |
@Test public void testMapKeys() { if(Config.isOSPOSIXCompatible()) { EditModeBuilder builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("M-a"), "meta"); assertEquals(builder.create().parse(Key.META_a).name(), new NoAction().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("M-[D"), "backward-char"); assertEquals(builder.create().parse(Key.LEFT).name(), new BackwardChar().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("M-[C"), "forward-char"); assertEquals(builder.create().parse(Key.RIGHT).name(), new ForwardChar().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("M-[A"), "previous-history"); assertEquals(builder.create().parse(Key.UP).name(), new PrevHistory().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("M-[B"), "next-history"); assertEquals(builder.create().parse(Key.DOWN).name(), new NextHistory().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("M-C-d"), "backward-char"); assertEquals(builder.create().parse(Key.META_CTRL_D).name(), new BackwardChar().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("C-M-D"), "forward-char"); assertEquals(builder.create().parse(Key.META_CTRL_D).name(), new ForwardChar().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("C-a"), "beginning-of-line"); assertEquals(builder.create().parse(Key.CTRL_A).name(), new BeginningOfLine().name()); builder = EditModeBuilder.builder(); builder.addAction(InputrcParser.mapKeys("C-?"), "backward-delete-char"); assertEquals(builder.create().parse(Key.BACKSPACE).name(), new DeletePrevChar().name()); } }
Example 19
Source File: Buffer.java From aesh-readline with Apache License 2.0 | 4 votes |
private void printInsertedData(Consumer<int[]> out, int width) { //print out prompt first if needed IntArrayBuilder builder = new IntArrayBuilder(); if(!isPromptDisplayed) { //only print the prompt if its longer than 0 if(promptLength() > 0) builder.append(prompt.getANSI()); isPromptDisplayed = true; //need to print the entire buffer //force that by setting delta = cursor if delta is 0 if(delta == 0) delta = cursor; } //quick exit if buffer is empty if(size == 0) { out.accept(builder.toArray()); return; } if(isMasking()) { if(prompt.getMask() != 0) { int[] mask = new int[delta]; Arrays.fill(mask, prompt.getMask()); builder.append(mask); } //a quick exit if we're masking with a no output mask else { out.accept(builder.toArray()); delta = 0; deltaChangedAtEndOfBuffer = true; } } else { if (deltaChangedAtEndOfBuffer) { if (delta == 1 || delta == 0) { if(cursor > 0) builder.append(new int[]{line[cursor - 1]}); else builder.append(new int[]{line[0]}); } else builder.append(Arrays.copyOfRange(line, cursor - delta, cursor)); } else { builder.append(Arrays.copyOfRange(line, cursor - delta, size)); } } //pad if we are at the end of the terminal if((size + promptLength()) % width == 0) { builder.append(new int[]{32, 13}); } //make sure we sync the cursor back if(!deltaChangedAtEndOfBuffer) { if((size + promptLength()) % width == 0 && (Config.isOSPOSIXCompatible() || (Config.isWindows() && WinSysTerminal.isVTSupported()))) { builder.append(syncCursorWhenBufferIsAtTerminalEdge(size + promptLength(), cursor + promptLength(), width)); } else builder.append(syncCursor(size + promptLength(), cursor + promptLength(), width)); } out.accept(builder.toArray()); delta = 0; deltaChangedAtEndOfBuffer = true; }