├── terminal-ssh ├── hostkey.ser └── src │ ├── main │ └── java │ │ └── org │ │ └── aesh │ │ └── terminal │ │ └── ssh │ │ ├── netty │ │ ├── NettyIoWriteFuture.java │ │ ├── NettyIoService.java │ │ ├── NettyIoHandlerBridge.java │ │ ├── AsyncUserAuthServiceFactory.java │ │ ├── AsyncAuth.java │ │ ├── Helper.java │ │ └── NettyIoServiceFactoryFactory.java │ │ └── SSHDevice.java │ └── test │ └── java │ └── org │ └── aesh │ └── terminal │ └── ssh │ ├── tty │ └── DefaultSshTtyTest.java │ ├── TestIoServiceFactoryFactory.java │ └── TestServiceFactory.java ├── .travis.yml ├── readline └── src │ ├── test │ ├── resources │ │ ├── ttytype_hpux.txt │ │ ├── inputrc1 │ │ ├── alias1 │ │ ├── inputrc2 │ │ └── input_stream.txt │ └── java │ │ └── org │ │ └── aesh │ │ └── readline │ │ ├── terminal │ │ └── formatting │ │ │ ├── TerminalTextStyleTest.java │ │ │ ├── TerminalStringTest.java │ │ │ └── TerminalColorTest.java │ │ ├── TestReadline.java │ │ ├── ParsingReadlineTest.java │ │ ├── util │ │ ├── WcWidthTest.java │ │ └── ShortHelperTest.java │ │ ├── PromptTest.java │ │ ├── MaskingReadlineTest.java │ │ ├── PasteReadlineTest.java │ │ ├── example │ │ └── SimpleTestExample.java │ │ └── completion │ │ └── CompleteOperationTest.java │ └── main │ └── java │ └── org │ └── aesh │ └── readline │ ├── ReadlineFlag.java │ ├── cursor │ ├── CursorListener.java │ └── CursorLocation.java │ ├── history │ ├── SearchDirection.java │ └── History.java │ ├── action │ ├── ActionEvent.java │ ├── Action.java │ ├── mappings │ │ ├── MoveBackwardBigWord.java │ │ ├── MoveForwardBigWord.java │ │ ├── MovementAction.java │ │ ├── ChangeForwardBigWord.java │ │ ├── DeleteForwardBigWord.java │ │ ├── ReverseSearchHistory.java │ │ ├── ChangeBackwardBigWord.java │ │ ├── DeleteBackwardBigWord.java │ │ ├── ForwardSearchHistory.java │ │ ├── NoAction.java │ │ ├── Clear.java │ │ ├── ForwardChar.java │ │ ├── BackwardChar.java │ │ ├── MoveBackwardWord.java │ │ ├── MoveForwardWord.java │ │ ├── EndOfLine.java │ │ ├── CopyForwardWord.java │ │ ├── BeginningOfLine.java │ │ ├── CopyBackwardWord.java │ │ ├── CopyLine.java │ │ ├── UpCaseForwardWord.java │ │ ├── CopyForwardBigWord.java │ │ ├── DeleteBackwardWord.java │ │ ├── ChangeForwardWord.java │ │ ├── DownCaseForwardWord.java │ │ ├── ChangeEndOfLine.java │ │ ├── CopyBackwardBigWord.java │ │ ├── CapitalizeForwardWord.java │ │ ├── ChangeBackwardWord.java │ │ ├── DeleteStartOfLine.java │ │ ├── DeleteForwardWord.java │ │ ├── UpCaseChar.java │ │ ├── Interrupt.java │ │ ├── DeleteLine.java │ │ ├── ChangeCaseChar.java │ │ ├── DeleteEndOfLine.java │ │ ├── EmacsEditingMode.java │ │ ├── Undo.java │ │ ├── NextHistory.java │ │ ├── PrevHistory.java │ │ ├── ViEditingMode.java │ │ ├── Yank.java │ │ ├── EndOfFile.java │ │ ├── DeleteChar.java │ │ └── BackwardBigWord.java │ ├── SearchAction.java │ └── KeyAction.java │ ├── terminal │ ├── impl │ │ ├── SignalHandlers.java │ │ ├── NativeSignalHandler.java │ │ ├── Pty.java │ │ ├── WinExternalTerminal.java │ │ └── AbstractPosixTerminal.java │ └── formatting │ │ ├── CharacterType.java │ │ └── Color.java │ ├── alias │ ├── AliasConflictException.java │ ├── AliasPreProcessor.java │ └── Alias.java │ ├── completion │ ├── SimpleCompletionHandler.java │ └── Completion.java │ ├── undo │ ├── UndoAction.java │ └── UndoManager.java │ ├── util │ ├── ShortHelper.java │ ├── IntArrayBuilder.java │ └── TerminalUtil.java │ └── paste │ └── PasteManager.java ├── .gitignore ├── terminal-api └── src │ ├── main │ ├── resources │ │ └── org │ │ │ └── aesh │ │ │ └── terminal │ │ │ └── utils │ │ │ ├── windows_caps.src │ │ │ ├── vt100_caps.src │ │ │ └── ansi_caps.src │ └── java │ │ └── org │ │ └── aesh │ │ └── terminal │ │ ├── Device.java │ │ ├── tty │ │ ├── Signal.java │ │ ├── Point.java │ │ └── TtyOutputMode.java │ │ └── Terminal.java │ └── test │ └── java │ └── org │ └── aesh │ └── terminal │ ├── utils │ └── CursesTest.java │ ├── tty │ └── TtyOutputModeTest.java │ └── io │ └── EncoderTest.java ├── terminal-http └── src │ ├── test │ └── java │ │ └── org │ │ └── aesh │ │ └── terminal │ │ └── http │ │ ├── Configurations.java │ │ ├── utils │ │ ├── ObjectWrapper.java │ │ ├── MockProcess.java │ │ └── Wait.java │ │ ├── server │ │ └── TaskStatusUpdateEventDeserializer.java │ │ └── tty │ │ └── NettyWebsocketTtyTest.java │ └── main │ ├── resources │ └── org │ │ └── aesh │ │ └── terminal │ │ └── http │ │ └── index.html │ └── java │ └── org │ └── aesh │ └── terminal │ └── http │ ├── Status.java │ └── HttpDevice.java └── terminal-telnet └── src ├── test └── java │ └── org │ └── aesh │ └── terminal │ └── telnet │ ├── NettyTelnetTermTest.java │ ├── NettyTelnetHandlerTest.java │ ├── TelnetTestBase.java │ └── tty │ ├── NettyBinaryTelnetTtyTest.java │ └── NettyAsciiTelnetTtyTest.java └── main └── java └── org └── aesh └── terminal └── telnet ├── util └── Helper.java ├── TelnetHandler.java ├── TelnetDevice.java └── netty └── NettyTelnetConnection.java /terminal-ssh/hostkey.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeshell/aesh-readline/HEAD/terminal-ssh/hostkey.ser -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk11 5 | 6 | notifications: 7 | irc: chat.freenode.net#aesh 8 | -------------------------------------------------------------------------------- /readline/src/test/resources/ttytype_hpux.txt: -------------------------------------------------------------------------------- 1 | TERM='vt200'; export TERM; 2 | LINES=47; export LINES; 3 | COLUMNS=112; export COLUMNS; 4 | ERASE='^?'; export ERASE; 5 | -------------------------------------------------------------------------------- /readline/src/test/resources/inputrc1: -------------------------------------------------------------------------------- 1 | 2 | set editing-mode vi 3 | 4 | set bell-style visible 5 | 6 | set disable-completion on 7 | 8 | set history-size 300 9 | 10 | -------------------------------------------------------------------------------- /readline/src/test/resources/alias1: -------------------------------------------------------------------------------- 1 | # some more ls aliases 2 | alias ll='ls -alF' 3 | alias la='ls -A' 4 | alias l='ls -CF' 5 | 6 | alias grep='grep --color=auto' 7 | alias fgrep='fgrep --color=auto' 8 | alias egrep='egrep --color=auto' 9 | -------------------------------------------------------------------------------- /readline/src/test/resources/inputrc2: -------------------------------------------------------------------------------- 1 | 2 | set editing-mode emacs 3 | 4 | set bell-style visible 5 | 6 | set disable-completion on 7 | 8 | set history-size 300 9 | 10 | "\M-[D": forward-char 11 | 12 | "\M-[B": previous-history 13 | 14 | Meta-Control-j: backward-char 15 | 16 | Control-a: forward-word -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore eclipse files 2 | .project 3 | .classpath 4 | .settings 5 | .metadata 6 | target 7 | 8 | # ignore IDEA files 9 | *.iml 10 | *.ipr 11 | *.iws 12 | .idea 13 | atlassian-ide-plugin.xml 14 | 15 | # ignore gradle build 16 | build 17 | .gradle 18 | out 19 | 20 | # ignore vim tmp files 21 | *.swp 22 | 23 | # ignore compile/test files 24 | classes 25 | /bin/ 26 | 27 | #ignore checkstile files 28 | .checkstyle 29 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/terminal/formatting/TerminalTextStyleTest.java: -------------------------------------------------------------------------------- 1 | package org.aesh.readline.terminal.formatting; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertFalse; 6 | import static org.junit.Assert.assertTrue; 7 | 8 | public class TerminalTextStyleTest { 9 | 10 | @Test 11 | public void testTerminalTextStyle() { 12 | TerminalTextStyle textStyle = new TerminalTextStyle(); 13 | 14 | assertFalse(textStyle.isBlink()); 15 | assertFalse(textStyle.isBold()); 16 | assertFalse(textStyle.isFormatted()); 17 | assertFalse(textStyle.isUnderline()); 18 | 19 | textStyle = new TerminalTextStyle(CharacterType.BOLD); 20 | assertFalse(textStyle.isBlink()); 21 | assertTrue(textStyle.isBold()); 22 | assertTrue(textStyle.isFormatted()); 23 | assertFalse(textStyle.isUnderline()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /readline/src/test/resources/input_stream.txt: -------------------------------------------------------------------------------- 1 | ffffffffffffffffffffffffffffffffff asdfdddddddddddddddddddddddddd 2 | aøsldkjfaoie jfaøldjfaeijf ølaeijf aije faøeif ja 3 | asdkjf aeøjfiaefiajfa oijfe aepoijfaæpojfe aeæifjaædi ofa 4 | 5 | 6 | aepofja alijfa peojfa pojfea poiefja oiefajdlkfnaeøijfa 7 | 8 | 9 | aoeifj øadjf aøoiefj aødoijfaø oiejfaøeoifja øjaef øaoeijfa øoejfia 10 | 11 | 12 | akwj ø1j2301923u984y043iu+10i3j hudhf oisajf+9u8hfiudanf 13 | 14 | cursor 15 | cursor 16 | cursor 17 | cursor 18 | cursor 19 | cursor 20 | cursor 21 | cursor 22 | cursor 23 | cursor 24 | cursor 25 | cursor 26 | cursor 27 | cursor 28 | 29 | 30 | cursor 31 | cursor 32 | cursor 33 | cursor 34 | cursor 35 | cursor 36 | cursor 37 | cursor 38 | cursor 39 | cursor 40 | cursor 41 | cursor 42 | cursor 43 | cursor 44 | 45 | 46 | 47 | 48 | foo bar badkfjas dfløkj123 49 | foo bar badkfjas dfløkj123 50 | foo bar badkfjas dfløkj123 51 | foo bar badkfjas dfløkj123 52 | 53 | 54 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/ReadlineFlag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Red Hat, Inc. and/or its affiliates. 3 | * 4 | * Licensed under the Eclipse Public License version 1.0, available at 5 | * http://www.eclipse.org/legal/epl-v10.html 6 | */ 7 | package org.aesh.readline; 8 | 9 | /** 10 | * @author Ståle W. Pedersen 11 | */ 12 | public enum ReadlineFlag { 13 | 14 | /** 15 | * Do not redraw prompt on INTR signal 16 | * 17 | * Default behaviour is to redraw . 18 | */ 19 | NO_PROMPT_REDRAW_ON_INTR, 20 | 21 | /** 22 | * Ignore EOF signal a given number of times 23 | */ 24 | IGNORE_EOF, 25 | 26 | /** 27 | * Do not activate multi-line mode 28 | * 33 | */ 34 | NO_MULTI_LINE_ON_QUOTE, 35 | 36 | /** 37 | * Do not discard lines starting with '#' 38 | */ 39 | NO_COMMENT_DISCARD 40 | 41 | } 42 | -------------------------------------------------------------------------------- /terminal-api/src/main/resources/org/aesh/terminal/utils/windows_caps.src: -------------------------------------------------------------------------------- 1 | windows|windows console compatibility, 2 | am, mc5i, mir, msgr, 3 | colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64, 4 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, 5 | cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B, 6 | cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 7 | cuu=\E[%p1%dA, cuu1=\E[A, 8 | dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, 9 | el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, 10 | ind=^J, 11 | invis=\E[8m, kbs=^H, kcbt=\E[Z, 12 | kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, 13 | khome=\E[H, 14 | op=\E[39;49m, 15 | rev=\E[7m, 16 | rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m, 17 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 18 | sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 19 | sgr0=\E[0;10m, 20 | smso=\E[7m, 21 | smul=\E[4m, 22 | kdch1=\E[3~, kich1=\E[2~, kend=\E[4~, knp=\E[6~, kpp=\E[5~, 23 | kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[15~, kf6=\E[17~, 24 | kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, 25 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/cursor/CursorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.cursor; 21 | 22 | /** 23 | * 24 | * @author jdenise@redhat.com 25 | */ 26 | public interface CursorListener { 27 | void moved(Line line); 28 | } 29 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/history/SearchDirection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.history; 21 | 22 | /** 23 | * 24 | * @author Ståle W. Pedersen 25 | */ 26 | public enum SearchDirection { 27 | REVERSE, 28 | FORWARD 29 | } 30 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/ActionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action; 21 | 22 | 23 | /** 24 | * @author Ståle W. Pedersen 25 | */ 26 | public interface ActionEvent extends Action { 27 | 28 | void input(Action action, KeyAction key); 29 | 30 | boolean keepFocus(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/terminal/impl/SignalHandlers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2018 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.impl; 21 | 22 | import org.aesh.terminal.Terminal.SignalHandler; 23 | 24 | /** 25 | * 26 | * @author jdenise@redhat.com 27 | */ 28 | public interface SignalHandlers { 29 | 30 | SignalHandler SIG_DFL = NativeSignalHandler.SIG_DFL; 31 | SignalHandler SIG_IGN = NativeSignalHandler.SIG_IGN; 32 | } 33 | -------------------------------------------------------------------------------- /terminal-api/src/main/resources/org/aesh/terminal/utils/vt100_caps.src: -------------------------------------------------------------------------------- 1 | vt100|vt100-am|dec vt100 (w/advanced video), 2 | OTbs, am, mc5i, msgr, xenl, xon, 3 | cols#80, it#8, lines#24, vt#3, 4 | acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, 5 | bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, 6 | clear=\E[H\E[J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, 7 | cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=^J, 8 | cuf=\E[%p1%dC, cuf1=\E[C$<2>, 9 | cup=\E[%i%p1%d;%p2%dH$<5>, cuu=\E[%p1%dA, 10 | cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>, el1=\E[1K$<3>, 11 | enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH, ind=^J, kbs=^H, 12 | kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, lf1=pf1, 13 | lf2=pf2, lf3=pf3, lf4=pf4, mc0=\E[0i, mc4=\E[4i, mc5=\E[5i, 14 | rc=\E8, rev=\E[7m$<2>, ri=\EM$<5>, rmacs=^O, rmam=\E[?7l, 15 | rmkx=\E[?1l\E>, rmso=\E[m$<2>, rmul=\E[m$<2>, 16 | rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, 17 | sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;$<2>, 18 | sgr0=\E[m\017$<2>, smacs=^N, smam=\E[?7h, smkx=\E[?1h\E=, 19 | smso=\E[7m$<2>, smul=\E[4m$<2>, tbc=\E[3g, 20 | use=vt100+fnkeys, 21 | vt100nam|vt100-nam|vt100 no automargins, 22 | am@, xenl@, use=vt100-am, 23 | vt100-vb|dec vt100 (w/advanced video) & no beep, 24 | bel@, flash=\E[?5h\E[?5l, use=vt100, 25 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/netty/NettyIoWriteFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.netty; 21 | 22 | import org.apache.sshd.common.io.AbstractIoWriteFuture; 23 | 24 | /** 25 | * @author Julien Viet 26 | */ 27 | public class NettyIoWriteFuture extends AbstractIoWriteFuture { 28 | 29 | public NettyIoWriteFuture() { 30 | super(null); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/alias/AliasConflictException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.alias; 21 | 22 | /** 23 | * @author Ståle Pedersen 24 | */ 25 | public class AliasConflictException extends Exception { 26 | 27 | public AliasConflictException() { 28 | } 29 | 30 | public AliasConflictException(String message) { 31 | super(message); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /terminal-http/src/test/java/org/aesh/terminal/http/Configurations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.http; 21 | 22 | /** 23 | * @author Matej Lazar 24 | */ 25 | public class Configurations { 26 | public static final String HOST = "localhost"; 27 | public static final String TERM_PATH = "/term"; 28 | public static final String PROCESS_UPDATES_PATH = "/process-status-updates"; 29 | } 30 | -------------------------------------------------------------------------------- /terminal-ssh/src/test/java/org/aesh/terminal/ssh/tty/DefaultSshTtyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.tty; 21 | 22 | import org.apache.sshd.server.SshServer; 23 | 24 | /** 25 | * @author Julien Viet 26 | */ 27 | public class DefaultSshTtyTest extends SshTtyTestBase { 28 | 29 | @Override 30 | protected SshServer createServer() { 31 | return SshServer.setUpDefaultServer(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | 24 | import java.util.function.Consumer; 25 | 26 | /** 27 | * @author Ståle W. Pedersen 28 | */ 29 | public interface Action extends Consumer { 30 | 31 | String name(); 32 | 33 | void accept(InputProcessor inputProcessor); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/completion/SimpleCompletionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.completion; 21 | 22 | /** 23 | * @author Ståle W. Pedersen 24 | */ 25 | public class SimpleCompletionHandler extends CompletionHandler { 26 | 27 | @Override 28 | public CompleteOperation createCompleteOperation(String buffer, int cursor) { 29 | return new CompleteOperationImpl(buffer, cursor); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /terminal-api/src/main/resources/org/aesh/terminal/utils/ansi_caps.src: -------------------------------------------------------------------------------- 1 | ansi|ansi/pc-term compatible with color, 2 | am, mc5i, mir, msgr, 3 | colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64, 4 | acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376, 5 | bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, 6 | cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B, 7 | cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, 8 | cuu=\E[%p1%dA, cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P, 9 | dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K, 10 | el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, ht=\E[I, hts=\EH, 11 | ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L, ind=^J, 12 | indn=\E[%p1%dS, invis=\E[8m, kbs=^H, kcbt=\E[Z, kcub1=\E[D, 13 | kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, kich1=\E[L, 14 | mc4=\E[4i, mc5=\E[5i, nel=\r\E[S, op=\E[39;49m, 15 | rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, rin=\E[%p1%dT, 16 | rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m, 17 | s0ds=\E(B, s1ds=\E)B, s2ds=\E*B, s3ds=\E+B, 18 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm, 19 | sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, 20 | sgr0=\E[0;10m, smacs=\E[11m, smpch=\E[11m, smso=\E[7m, 21 | smul=\E[4m, tbc=\E[2g, u6=\E[%i%d;%dR, u7=\E[6n, 22 | u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd, 23 | 24 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/terminal/formatting/TerminalStringTest.java: -------------------------------------------------------------------------------- 1 | package org.aesh.readline.terminal.formatting; 2 | 3 | import org.aesh.terminal.utils.ANSI; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertFalse; 8 | import static org.junit.Assert.assertTrue; 9 | 10 | public class TerminalStringTest { 11 | 12 | @Test 13 | public void testTerminalString() { 14 | TerminalString string = new TerminalString("foo"); 15 | 16 | assertFalse(string.containSpaces()); 17 | assertFalse(string.isFormatted()); 18 | assertEquals("foo", string.getCharacters()); 19 | 20 | string = new TerminalString("foo bar", new TerminalColor(Color.BLACK, Color.WHITE)); 21 | assertTrue(string.containSpaces()); 22 | assertTrue(string.isFormatted()); 23 | assertEquals("foo bar", string.getCharacters()); 24 | string.switchSpacesToEscapedSpaces(); 25 | assertEquals("foo\\ bar", string.getCharacters()); 26 | assertEquals(ANSI.START+";30;47mfoo\\ bar"+ANSI.RESET, string.toString()); 27 | 28 | string = new TerminalString("foo bar", true); 29 | assertTrue(string.containSpaces()); 30 | assertFalse(string.isFormatted()); 31 | assertEquals("foo bar", string.getCharacters()); 32 | 33 | assertEquals(0, string.getANSILength()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/MoveBackwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class MoveBackwardBigWord extends BackwardBigWord { 28 | 29 | public MoveBackwardBigWord() { 30 | super(EditMode.Status.MOVE); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "backward-big-word"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/MoveForwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class MoveForwardBigWord extends ForwardBigWord { 28 | 29 | public MoveForwardBigWord() { 30 | super(EditMode.Status.MOVE); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "move-forward-big-word"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/MovementAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.action.Action; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | abstract class MovementAction implements Action { 28 | 29 | protected boolean isSpace(char c) { 30 | return Character.isWhitespace(c); 31 | } 32 | 33 | protected boolean isDelimiter(char c) { 34 | return !Character.isLetterOrDigit(c); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ChangeForwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class ChangeForwardBigWord extends ForwardBigWord { 28 | 29 | public ChangeForwardBigWord() { 30 | super(EditMode.Status.CHANGE); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "change-forward-big-word"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteForwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class DeleteForwardBigWord extends ForwardBigWord { 28 | 29 | public DeleteForwardBigWord() { 30 | super(EditMode.Status.DELETE); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "delete-forward-big-word"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ReverseSearchHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.action.SearchAction; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class ReverseSearchHistory extends SearchHistory { 28 | 29 | ReverseSearchHistory() { 30 | super(SearchAction.Status.SEARCH_PREV); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "reverse-search-history"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ChangeBackwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class ChangeBackwardBigWord extends BackwardBigWord { 28 | 29 | public ChangeBackwardBigWord() { 30 | super(EditMode.Status.CHANGE); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "change-backward-big-word"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteBackwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class DeleteBackwardBigWord extends BackwardBigWord { 28 | 29 | public DeleteBackwardBigWord() { 30 | super(EditMode.Status.DELETE); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "delete-backward-big-word"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ForwardSearchHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.action.SearchAction; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class ForwardSearchHistory extends SearchHistory { 28 | 29 | ForwardSearchHistory() { 30 | super(SearchAction.Status.SEARCH_NEXT); 31 | } 32 | 33 | @Override 34 | public String name() { 35 | return "forward-search-history"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/NoAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class NoAction implements Action { 29 | @Override 30 | public String name() { 31 | return "no-action"; 32 | } 33 | 34 | @Override 35 | public void accept(InputProcessor inputProcessor) { 36 | //do nothing 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/completion/Completion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.completion; 21 | 22 | /** 23 | * To enable auto completion, commands need to implement this interface. 24 | * 25 | * @author Ståle W. Pedersen 26 | */ 27 | public interface Completion { 28 | 29 | /** 30 | * Populate the CompleteOperation object with possible 31 | * completions + offset if needed 32 | * 33 | * @param completeOperation operation 34 | */ 35 | void complete(C completeOperation); 36 | } 37 | -------------------------------------------------------------------------------- /terminal-http/src/test/java/org/aesh/terminal/http/utils/ObjectWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.http.utils; 21 | 22 | 23 | /** 24 | * Created by Matej Lazar on 2014-12-09. 25 | */ 26 | public class ObjectWrapper { 27 | private T obj; 28 | 29 | public ObjectWrapper() { 30 | } 31 | 32 | public ObjectWrapper(T obj) { 33 | this.obj = obj; 34 | } 35 | 36 | public void set(T obj) { 37 | this.obj = obj; 38 | } 39 | 40 | public T get() { 41 | return obj; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/TestReadline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class TestReadline extends Readline { 28 | 29 | public TestReadline() { 30 | super(); 31 | } 32 | 33 | public TestReadline(EditMode editMode) { 34 | super(editMode); 35 | } 36 | 37 | public String getBuffer() { 38 | return getInputProcessor().buffer().buffer().asString(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/Clear.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class Clear implements Action { 29 | @Override 30 | public String name() { 31 | return "clear-screen"; 32 | } 33 | 34 | @Override 35 | public void accept(InputProcessor inputProcessor) { 36 | inputProcessor.buffer().clear(true); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ForwardChar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class ForwardChar implements Action { 29 | 30 | @Override 31 | public String name() { 32 | return "forward-char"; 33 | } 34 | 35 | @Override 36 | public void accept(InputProcessor inputProcessor) { 37 | inputProcessor.buffer().moveCursor(1); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/BackwardChar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class BackwardChar implements Action { 29 | 30 | @Override 31 | public String name() { 32 | return "backward-char"; 33 | } 34 | 35 | @Override 36 | public void accept(InputProcessor inputProcessor) { 37 | inputProcessor.buffer().moveCursor(-1); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/MoveBackwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class MoveBackwardWord extends BackwardWord { 28 | 29 | public MoveBackwardWord() { 30 | super(); 31 | } 32 | 33 | public MoveBackwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.MOVE); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "backward-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/MoveForwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class MoveForwardWord extends ForwardWord { 29 | 30 | public MoveForwardWord() { 31 | super(); 32 | } 33 | 34 | public MoveForwardWord(boolean viMode) { 35 | super(viMode, EditMode.Status.MOVE); 36 | } 37 | 38 | @Override 39 | public String name() { 40 | return "forward-word"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/EndOfLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class EndOfLine implements Action { 29 | @Override 30 | public String name() { 31 | return "end-of-line"; 32 | } 33 | 34 | @Override 35 | public void accept(InputProcessor inputProcessor) { 36 | inputProcessor.buffer().moveCursor(inputProcessor.buffer().buffer().length()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/terminal/impl/NativeSignalHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.impl; 21 | 22 | import org.aesh.terminal.Terminal; 23 | import org.aesh.terminal.tty.Signal; 24 | 25 | public final class NativeSignalHandler implements Terminal.SignalHandler { 26 | 27 | public static final NativeSignalHandler SIG_DFL = new NativeSignalHandler(); 28 | 29 | public static final NativeSignalHandler SIG_IGN = new NativeSignalHandler(); 30 | 31 | private NativeSignalHandler() { 32 | } 33 | 34 | public void handle(Signal signal) { 35 | throw new UnsupportedOperationException(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/CopyForwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class CopyForwardWord extends ForwardWord { 28 | 29 | public CopyForwardWord() { 30 | super(false, EditMode.Status.YANK); 31 | } 32 | 33 | public CopyForwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.YANK); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "copy-forward-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /terminal-ssh/src/test/java/org/aesh/terminal/ssh/TestIoServiceFactoryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh; 21 | 22 | import org.apache.sshd.common.FactoryManager; 23 | import org.apache.sshd.common.io.IoServiceFactory; 24 | import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory; 25 | 26 | /** 27 | * @author Julien Viet 28 | */ 29 | public class TestIoServiceFactoryFactory extends Nio2ServiceFactoryFactory { 30 | 31 | @Override 32 | public IoServiceFactory create(FactoryManager manager) { 33 | return new TestServiceFactory(manager, getExecutorService(), isShutdownOnExit()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/BeginningOfLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class BeginningOfLine implements Action { 29 | @Override 30 | public String name() { 31 | return "beginning-of-line"; 32 | } 33 | 34 | @Override 35 | public void accept(InputProcessor inputProcessor) { 36 | inputProcessor.buffer().moveCursor(-inputProcessor.buffer().buffer().length()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/CopyBackwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class CopyBackwardWord extends BackwardWord { 28 | 29 | public CopyBackwardWord() { 30 | super(false, EditMode.Status.YANK); 31 | } 32 | 33 | public CopyBackwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.YANK); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "copy-backward-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/CopyLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.readline.action.mappings; 22 | 23 | import org.aesh.readline.InputProcessor; 24 | import org.aesh.readline.action.Action; 25 | 26 | /** 27 | * @author Ståle W. Pedersen 28 | */ 29 | public class CopyLine implements Action { 30 | 31 | @Override 32 | public String name() { 33 | return "copy-line"; 34 | } 35 | 36 | @Override 37 | public void accept(InputProcessor inputProcessor) { 38 | inputProcessor.buffer().pasteManager().addText(inputProcessor.buffer().buffer().multiLine()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/UpCaseForwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class UpCaseForwardWord extends ForwardWord { 28 | 29 | public UpCaseForwardWord() { 30 | super(false, EditMode.Status.UP_CASE); 31 | } 32 | 33 | public UpCaseForwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.UP_CASE); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "upcase-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/cursor/CursorLocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.cursor; 21 | 22 | /** 23 | * 24 | * @author jdenise@redhat.com 25 | */ 26 | public class CursorLocation { 27 | 28 | private final int column; 29 | private final int row; 30 | 31 | public CursorLocation(int row, int column) { 32 | this.row = row; 33 | this.column = column; 34 | } 35 | 36 | /** 37 | * @return the column 38 | */ 39 | public int getColumn() { 40 | return column; 41 | } 42 | 43 | /** 44 | * @return the row 45 | */ 46 | public int getRow() { 47 | return row; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /terminal-http/src/main/resources/org/aesh/terminal/http/index.html: -------------------------------------------------------------------------------- 1 | 2 | Æsh Readline 3 | 4 |

Æsh Readline

5 | 6 | 30 | 31 | 32 | 55 | 56 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/CopyForwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.readline.action.mappings; 22 | 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class CopyForwardBigWord extends ForwardBigWord { 29 | 30 | public CopyForwardBigWord() { 31 | super(EditMode.Status.YANK); 32 | } 33 | 34 | public CopyForwardBigWord(boolean viMode) { 35 | super(viMode, EditMode.Status.YANK); 36 | } 37 | 38 | @Override 39 | public String name() { 40 | return "copy-forward-big-word"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteBackwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class DeleteBackwardWord extends BackwardWord { 28 | 29 | public DeleteBackwardWord() { 30 | super(false, EditMode.Status.DELETE); 31 | } 32 | 33 | public DeleteBackwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.DELETE); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "backward-kill-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ChangeForwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class ChangeForwardWord extends ForwardWord { 28 | 29 | public ChangeForwardWord() { 30 | super(false, EditMode.Status.CHANGE); 31 | } 32 | 33 | public ChangeForwardWord(boolean viMode, EditMode.Status status) { 34 | super(viMode, status); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "change-forward-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DownCaseForwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class DownCaseForwardWord extends ForwardWord { 28 | 29 | public DownCaseForwardWord() { 30 | super(false, EditMode.Status.DOWN_CASE); 31 | } 32 | 33 | public DownCaseForwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.DOWN_CASE); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "downcase-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /terminal-http/src/main/java/org/aesh/terminal/http/Status.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.http; 21 | 22 | /** 23 | * @author Matej Lazar 24 | */ 25 | public enum Status { 26 | 27 | NEW (false), 28 | RUNNING (false), 29 | COMPLETED (true), 30 | FAILED (true), 31 | INTERRUPTED (true); 32 | 33 | private final boolean final_; 34 | 35 | Status(boolean finalFlag) { 36 | this.final_ = finalFlag; 37 | } 38 | 39 | /** 40 | * @return true when master won't wait anymore for the process to end, the process may have terminated or not. 41 | */ 42 | public boolean isFinal() { 43 | return final_; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ChangeEndOfLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class ChangeEndOfLine extends ChangeAction { 29 | 30 | public ChangeEndOfLine() { 31 | super(EditMode.Status.CHANGE); 32 | } 33 | 34 | @Override 35 | public String name() { 36 | return "change-end-of-line"; 37 | } 38 | 39 | @Override 40 | public void accept(InputProcessor inputProcessor) { 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/CopyBackwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.readline.action.mappings; 22 | 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class CopyBackwardBigWord extends BackwardBigWord { 29 | 30 | public CopyBackwardBigWord() { 31 | super(false, EditMode.Status.YANK); 32 | } 33 | 34 | public CopyBackwardBigWord(boolean viMode) { 35 | super(viMode, EditMode.Status.YANK); 36 | } 37 | 38 | @Override 39 | public String name() { 40 | return "copy-backward-big-word"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/terminal/formatting/CharacterType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.formatting; 21 | 22 | /** 23 | * Define what kind of character type to display 24 | * 25 | * @author Ståle W. Pedersen 26 | */ 27 | public enum CharacterType { 28 | BOLD(1), 29 | FAINT(2), 30 | ITALIC(3), 31 | UNDERLINE(4), 32 | BLINK(5), 33 | INVERT(7), 34 | CONCEAL(8), 35 | CROSSED_OUT(9); 36 | 37 | private final int value; 38 | 39 | CharacterType(int c) { 40 | this.value = c; 41 | } 42 | 43 | public int getValue() { 44 | return value; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/CapitalizeForwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class CapitalizeForwardWord extends ForwardWord { 28 | 29 | public CapitalizeForwardWord() { 30 | super(false, EditMode.Status.CAPITALIZE); 31 | } 32 | 33 | public CapitalizeForwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.CAPITALIZE); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "capitalize-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ChangeBackwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class ChangeBackwardWord extends BackwardWord { 28 | 29 | public ChangeBackwardWord(EditMode.Status status) { 30 | super(false, status); 31 | } 32 | 33 | public ChangeBackwardWord(boolean viMode, EditMode.Status status) { 34 | super(viMode, status); 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "change-backward-word"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /terminal-telnet/src/test/java/org/aesh/terminal/telnet/NettyTelnetTermTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.terminal.telnet; 22 | 23 | import java.io.Closeable; 24 | import java.util.function.Function; 25 | import java.util.function.Supplier; 26 | 27 | /** 28 | * See Julien Viet 31 | */ 32 | public class NettyTelnetTermTest extends TelnetTermTest { 33 | 34 | @Override 35 | protected Function, Closeable> serverFactory() { 36 | return TelnetServerRule.NETTY_SERVER; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /terminal-telnet/src/test/java/org/aesh/terminal/telnet/NettyTelnetHandlerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.terminal.telnet; 22 | 23 | import java.io.Closeable; 24 | import java.util.function.Function; 25 | import java.util.function.Supplier; 26 | 27 | /** 28 | * See Julien Viet 31 | */ 32 | public class NettyTelnetHandlerTest extends TelnetHandlerTest { 33 | 34 | @Override 35 | protected Function, Closeable> serverFactory() { 36 | return TelnetServerRule.NETTY_SERVER; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/SearchAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action; 21 | 22 | /** 23 | * @author Ståle W. Pedersen 24 | */ 25 | public interface SearchAction extends ActionEvent { 26 | 27 | enum Status { 28 | SEARCH_NOT_STARTED, 29 | SEARCH_EXIT, 30 | SEARCH_INPUT, 31 | SEARCH_INTERRUPT, 32 | SEARCH_END, 33 | SEARCH_PREV, 34 | SEARCH_NEXT, 35 | SEARCH_DELETE, 36 | SEARCH_MOVE_PREV, 37 | SEARCH_MOVE_NEXT, 38 | SEARCH_MOVE_RIGHT, 39 | SEARCH_MOVE_LEFT, 40 | SEARCH_MOVE_BEGINNING_OF_LINE, 41 | SEARCH_MOVE_END_OF_LINE, 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteStartOfLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class DeleteStartOfLine extends ChangeAction { 29 | 30 | public DeleteStartOfLine() { 31 | super(EditMode.Status.DELETE); 32 | } 33 | 34 | @Override 35 | public String name() { 36 | return "backward-kill-line"; 37 | } 38 | 39 | @Override 40 | public void accept(InputProcessor inputProcessor) { 41 | apply(0, inputProcessor); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /terminal-telnet/src/test/java/org/aesh/terminal/telnet/TelnetTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.terminal.telnet; 22 | 23 | import org.aesh.terminal.TestBase; 24 | import org.junit.Rule; 25 | 26 | import java.io.Closeable; 27 | import java.util.function.Function; 28 | import java.util.function.Supplier; 29 | 30 | /** 31 | * @author Julien Viet 32 | */ 33 | public abstract class TelnetTestBase extends TestBase { 34 | 35 | @Rule 36 | public TelnetServerRule server = new TelnetServerRule(serverFactory()); 37 | 38 | @Rule 39 | public TelnetClientRule client = new TelnetClientRule(); 40 | 41 | protected abstract Function, Closeable> serverFactory(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/ParsingReadlineTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline; 21 | 22 | import org.aesh.readline.tty.terminal.TestConnection; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | /** 28 | * @author Ståle W. Pedersen 29 | */ 30 | public class ParsingReadlineTest { 31 | 32 | @Test 33 | public void testParse() { 34 | TestConnection connection = new TestConnection(); 35 | connection.read(new byte[] {'3', '4', 1, 27}); 36 | assertEquals(": 34", connection.getOutputBuffer()); 37 | connection.read(new byte[]{91, 67, '1', '2', '\r'}); 38 | connection.assertLine("[C1234"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /terminal-api/src/test/java/org/aesh/terminal/utils/CursesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.utils; 21 | 22 | import org.junit.Test; 23 | 24 | import java.io.StringWriter; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | 28 | /** 29 | * @author Guillaume Nodet 30 | */ 31 | public class CursesTest { 32 | 33 | @Test 34 | public void testTputs() throws Exception { 35 | 36 | assertEquals("\033[3;4r", tputs("\\E[%i%p1%d;%p2%dr", 2, 3)); 37 | 38 | } 39 | 40 | private String tputs(String cap, Object... params) throws Exception { 41 | StringWriter sw = new StringWriter(); 42 | Curses.tputs(sw, cap, params); 43 | return sw.toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /terminal-api/src/main/java/org/aesh/terminal/Device.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal; 21 | 22 | import org.aesh.terminal.tty.Capability; 23 | 24 | import java.util.function.Consumer; 25 | 26 | /** 27 | * Contains info regarding the current device connected to readline 28 | * 29 | * @author Ståle W. Pedersen 30 | */ 31 | public interface Device { 32 | 33 | String type(); 34 | 35 | boolean getBooleanCapability(Capability capability); 36 | 37 | Integer getNumericCapability(Capability capability); 38 | 39 | String getStringCapability(Capability capability); 40 | 41 | int[] getStringCapabilityAsInts(Capability capability); 42 | 43 | boolean puts(Consumer output, Capability capability); 44 | } 45 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/alias/AliasPreProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.alias; 21 | 22 | import java.util.Optional; 23 | import java.util.function.Function; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class AliasPreProcessor implements Function> { 29 | 30 | private final AliasManager manager; 31 | 32 | public AliasPreProcessor(AliasManager manager) { 33 | this.manager = manager; 34 | } 35 | 36 | @Override 37 | public Optional apply(String input) { 38 | //return manager.getAliasName(input); 39 | Optional out = manager.getAliasName(input); 40 | return out; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteForwardWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.editing.EditMode; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class DeleteForwardWord extends ForwardWord { 28 | 29 | public DeleteForwardWord() { 30 | super(false, EditMode.Status.DELETE); 31 | } 32 | 33 | public DeleteForwardWord(boolean viMode) { 34 | super(viMode, EditMode.Status.DELETE); 35 | } 36 | 37 | public DeleteForwardWord(boolean viMode, EditMode.Status status) { 38 | super(viMode, status); 39 | } 40 | 41 | @Override 42 | public String name() { 43 | return "kill-word"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/util/WcWidthTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.util; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class WcWidthTest { 29 | 30 | @Test 31 | public void testWidth() { 32 | //assertEquals(1, WcWidth.width('æ')); 33 | assertEquals(1, WcWidth.width('s')); 34 | assertEquals(1, WcWidth.width('h')); 35 | assertEquals(0, WcWidth.width('\0')); 36 | assertEquals(-1, WcWidth.width('\n')); 37 | assertEquals(-1, WcWidth.width('\r')); 38 | assertEquals(-1, WcWidth.width('\t')); 39 | assertEquals(-1, WcWidth.width('\u001B')); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/terminal/impl/Pty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.impl; 21 | 22 | import org.aesh.terminal.Attributes; 23 | 24 | import java.io.Closeable; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | import org.aesh.terminal.tty.Size; 29 | 30 | public interface Pty extends Closeable { 31 | 32 | InputStream getMasterInput() throws IOException; 33 | 34 | OutputStream getMasterOutput() throws IOException; 35 | 36 | InputStream getSlaveInput() throws IOException; 37 | 38 | OutputStream getSlaveOutput() throws IOException; 39 | 40 | Attributes getAttr() throws IOException; 41 | 42 | void setAttr(Attributes attr) throws IOException; 43 | 44 | Size getSize() throws IOException; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/UpCaseChar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class UpCaseChar implements Action { 29 | 30 | @Override 31 | public String name() { 32 | return "upcase-char"; 33 | } 34 | 35 | @Override 36 | public void accept(InputProcessor inputProcessor) { 37 | if(inputProcessor.buffer().buffer().length() >= 38 | inputProcessor.buffer().buffer().cursor()) { 39 | inputProcessor.buffer().addActionToUndoStack(); 40 | inputProcessor.buffer().upCase(); 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/Interrupt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | import org.aesh.terminal.tty.Signal; 25 | 26 | /** 27 | * @author Ståle W. Pedersen 28 | */ 29 | public class Interrupt implements Action { 30 | 31 | @Override 32 | public String name() { 33 | return "interrupt"; 34 | } 35 | 36 | @Override 37 | public void accept(InputProcessor inputProcessor) { 38 | //if the terminal cant raise the int signal, we'll do it manually 39 | if(inputProcessor.connection().getSignalHandler() != null) 40 | inputProcessor.connection().getSignalHandler().accept(Signal.INT); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/netty/NettyIoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.netty; 21 | 22 | import org.apache.sshd.common.io.IoService; 23 | import org.apache.sshd.common.io.IoSession; 24 | import org.apache.sshd.common.util.CloseableUtils; 25 | 26 | import java.util.Map; 27 | import java.util.concurrent.ConcurrentHashMap; 28 | import java.util.concurrent.atomic.AtomicLong; 29 | 30 | /** 31 | * @author Julien Viet 32 | */ 33 | public class NettyIoService extends CloseableUtils.AbstractCloseable implements IoService { 34 | 35 | final AtomicLong sessionSeq = new AtomicLong(); 36 | final Map sessions = new ConcurrentHashMap<>(); 37 | 38 | @Override 39 | public Map getManagedSessions() { 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/undo/UndoAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.undo; 21 | 22 | /** 23 | * @author Ståle W. Pedersen 24 | */ 25 | public class UndoAction { 26 | 27 | private int cursorPosition; 28 | private int[] buffer; 29 | 30 | public UndoAction(int cursorPosition, int[] buffer) { 31 | setCursorPosition(cursorPosition); 32 | setBuffer(buffer); 33 | } 34 | 35 | public int getCursorPosition() { 36 | return cursorPosition; 37 | } 38 | 39 | private void setCursorPosition(int cursorPosition) { 40 | this.cursorPosition = cursorPosition; 41 | } 42 | 43 | public int[] getBuffer() { 44 | return buffer; 45 | } 46 | 47 | private void setBuffer(int[] buffer) { 48 | this.buffer = buffer; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class DeleteLine extends ChangeAction { 29 | 30 | 31 | DeleteLine() { 32 | super(EditMode.Status.DELETE); 33 | } 34 | 35 | DeleteLine(boolean viMode) { 36 | super(viMode, EditMode.Status.DELETE); 37 | } 38 | 39 | @Override 40 | public String name() { 41 | return "kill-whole-line"; 42 | } 43 | 44 | @Override 45 | public void accept(InputProcessor inputProcessor) { 46 | apply(0, inputProcessor.buffer().buffer().length(), inputProcessor); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /terminal-telnet/src/main/java/org/aesh/terminal/telnet/util/Helper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.telnet.util; 21 | 22 | import java.util.concurrent.CompletableFuture; 23 | import java.util.function.Consumer; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class Helper { 29 | 30 | public static Consumer startedHandler(CompletableFuture fut) { 31 | return err -> { 32 | if (err == null) { 33 | fut.complete(null); 34 | } else { 35 | fut.completeExceptionally(err); 36 | } 37 | }; 38 | } 39 | 40 | public static Consumer stoppedHandler(CompletableFuture fut) { 41 | return err -> { 42 | fut.complete(null); 43 | }; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/util/ShortHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.util; 21 | 22 | /** 23 | * @author Ståle W. Pedersen 24 | */ 25 | public class ShortHelper { 26 | 27 | public static short[] toShortPoints(String input) { 28 | short[] out = new short[input.length()]; 29 | final int[] counter = {0}; 30 | input.chars().forEach( i -> { 31 | out[counter[0]] = (short) i; 32 | counter[0]++; 33 | }); 34 | return out; 35 | } 36 | 37 | public static String fromShortPoints(short[] input) { 38 | char[] output = new char[input.length]; 39 | for(int i=0; i < input.length; i++) 40 | output[i] = (char) input[i]; 41 | 42 | return new String(output, 0, output.length); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/PromptTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertFalse; 25 | import static org.junit.Assert.assertTrue; 26 | 27 | public class PromptTest { 28 | 29 | @Test 30 | public void testEquals() { 31 | Prompt p1 = new Prompt("[foo@bar]"); 32 | Prompt p2 = new Prompt("[disconnected]"); 33 | 34 | assertFalse(p1.equals(p2)); 35 | p1 = new Prompt("[disconnected]"); 36 | assertTrue(p1.equals(p2)); 37 | 38 | p1 = new Prompt("[disconnected]", '\0'); 39 | assertFalse(p1.equals(p2)); 40 | 41 | p2 = new Prompt("[disconnected]", '#'); 42 | assertFalse(p1.equals(p2)); 43 | p1 = new Prompt("[disconnected]", '#'); 44 | assertTrue(p1.equals(p2)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/terminal/formatting/TerminalColorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.formatting; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertFalse; 26 | import static org.junit.Assert.assertTrue; 27 | 28 | /** 29 | * @author Ståle W. Pedersen 30 | */ 31 | public class TerminalColorTest { 32 | 33 | @Test 34 | public void testTerminalColor() { 35 | TerminalColor color = new TerminalColor( Color.DEFAULT, Color.BLACK); 36 | 37 | assertEquals("3"+Color.DEFAULT.getValue()+";4"+Color.BLACK.getValue(), color.toString()); 38 | 39 | assertTrue(color.isFormatted()); 40 | 41 | color = new TerminalColor(); 42 | assertFalse(color.isFormatted()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/netty/NettyIoHandlerBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.netty; 21 | 22 | import org.apache.sshd.common.io.IoHandler; 23 | import org.apache.sshd.common.io.IoSession; 24 | import org.apache.sshd.common.util.Readable; 25 | 26 | /** 27 | * @author Julien Viet 28 | */ 29 | public class NettyIoHandlerBridge { 30 | 31 | public void sessionCreated(IoHandler handler, IoSession session) throws Exception { 32 | handler.sessionCreated(session); 33 | } 34 | 35 | public void sessionClosed(IoHandler handler, IoSession session) throws Exception { 36 | handler.sessionClosed(session); 37 | } 38 | 39 | public void messageReceived(IoHandler handler, IoSession session, Readable message) throws Exception { 40 | handler.messageReceived(session, message); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/terminal/impl/WinExternalTerminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.impl; 21 | 22 | import org.aesh.terminal.Attributes; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | 28 | /** 29 | * @author Ståle W. Pedersen 30 | */ 31 | public class WinExternalTerminal extends ExternalTerminal { 32 | 33 | public WinExternalTerminal(String name, String type, InputStream masterInput, OutputStream masterOutput) throws IOException { 34 | super(name, type, masterInput, masterOutput); 35 | Attributes attributes = new Attributes(); 36 | attributes.setInputFlag(Attributes.InputFlag.IGNCR, true); 37 | attributes.setInputFlag(Attributes.InputFlag.ICRNL, true); 38 | setAttributes(attributes); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ChangeCaseChar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.readline.action.mappings; 22 | 23 | import org.aesh.readline.InputProcessor; 24 | import org.aesh.readline.action.Action; 25 | 26 | /** 27 | * @author Ståle W. Pedersen 28 | */ 29 | public class ChangeCaseChar implements Action { 30 | @Override 31 | public String name() { 32 | return "change-case-char"; 33 | } 34 | 35 | @Override 36 | public void accept(InputProcessor inputProcessor) { 37 | if(inputProcessor.buffer().buffer().length() >= 38 | inputProcessor.buffer().buffer().cursor()) { 39 | inputProcessor.buffer().addActionToUndoStack(); 40 | inputProcessor.buffer().changeCase(); 41 | inputProcessor.buffer().moveCursor(1); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteEndOfLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class DeleteEndOfLine extends ChangeAction { 29 | 30 | public DeleteEndOfLine() { 31 | super(EditMode.Status.DELETE); 32 | } 33 | 34 | public DeleteEndOfLine(boolean viMode) { 35 | super(viMode, EditMode.Status.DELETE); 36 | } 37 | 38 | @Override 39 | public String name() { 40 | return "kill-line"; 41 | } 42 | 43 | @Override 44 | public void accept(InputProcessor inputProcessor) { 45 | int cursor = inputProcessor.buffer().buffer().length(); 46 | apply(cursor, inputProcessor); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/EmacsEditingMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | import org.aesh.readline.editing.EditMode; 25 | import org.aesh.readline.editing.EditModeBuilder; 26 | 27 | /** 28 | * @author Ståle W. Pedersen 29 | */ 30 | public class EmacsEditingMode implements Action { 31 | 32 | EmacsEditingMode() { 33 | } 34 | 35 | @Override 36 | public String name() { 37 | return "emacs-editing-mode"; 38 | } 39 | 40 | @Override 41 | public void accept(InputProcessor inputProcessor) { 42 | if(inputProcessor.editMode().mode() != EditMode.Mode.EMACS) 43 | inputProcessor.setEditMode(EditModeBuilder.builder(EditMode.Mode.EMACS).create()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/netty/AsyncUserAuthServiceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.netty; 21 | 22 | import org.apache.sshd.common.Service; 23 | import org.apache.sshd.common.ServiceFactory; 24 | import org.apache.sshd.common.session.Session; 25 | 26 | import java.io.IOException; 27 | 28 | /** 29 | * @author Julien Viet 30 | */ 31 | public class AsyncUserAuthServiceFactory implements ServiceFactory { 32 | public static final AsyncUserAuthServiceFactory INSTANCE = new AsyncUserAuthServiceFactory(); 33 | 34 | public AsyncUserAuthServiceFactory() { 35 | super(); 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return "ssh-userauth"; 41 | } 42 | 43 | @Override 44 | public Service create(Session session) throws IOException { 45 | return new AsyncUserAuthService(session); 46 | } 47 | } -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/Undo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | import org.aesh.readline.undo.UndoAction; 25 | 26 | /** 27 | * @author Ståle W. Pedersen 28 | */ 29 | public class Undo implements Action { 30 | 31 | @Override 32 | public String name() { 33 | return "undo"; 34 | } 35 | 36 | @Override 37 | public void accept(InputProcessor inputProcessor) { 38 | UndoAction ua = inputProcessor.buffer().undoManager().getNext(); 39 | if(ua != null) { 40 | inputProcessor.buffer().replace(ua.getBuffer()); 41 | inputProcessor.buffer().moveCursor(ua.getCursorPosition() - 42 | inputProcessor.buffer().buffer().cursor()); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /terminal-api/src/main/java/org/aesh/terminal/tty/Signal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.tty; 21 | 22 | /** 23 | * @author Ståle W. Pedersen 24 | */ 25 | public enum Signal { 26 | /** 27 | * Interrupt, usually caused by Ctrl-c or the ASCII code 3 28 | */ 29 | INT, 30 | /** 31 | * Usually works like INT, caused by Ctrl-\ 32 | */ 33 | QUIT, 34 | /** 35 | * Works like INT and QUIT, caused by Ctrl-z. 36 | * The default action is to suspend the process. 37 | */ 38 | SUSP, 39 | /** 40 | * End of file, first send end-of-file, then causes the next read to send end of file. 41 | * Ctrl-d by default. 42 | */ 43 | EOF, 44 | /** 45 | * Wake up. This will un-suspend a stopped process. 46 | */ 47 | CONT, 48 | /** 49 | * 50 | */ 51 | INFO, 52 | /** 53 | * Window resize 54 | */ 55 | WINCH 56 | } 57 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/KeyAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action; 21 | 22 | import java.nio.IntBuffer; 23 | 24 | /** 25 | * Represents a key value. 26 | * 27 | */ 28 | public interface KeyAction { 29 | 30 | default IntBuffer buffer() { 31 | int length = length(); 32 | IntBuffer buf = IntBuffer.allocate(length); 33 | for (int i = 0;i < length;i++) { 34 | buf.put(getCodePointAt(i)); 35 | } 36 | buf.flip(); 37 | return buf; 38 | } 39 | 40 | int getCodePointAt(int index) throws IndexOutOfBoundsException; 41 | 42 | int length(); 43 | 44 | String name(); 45 | 46 | default boolean bufferEquals(KeyAction otherAction) { 47 | if(length() == otherAction.length()) { 48 | for(int i=0; iStåle W. Pedersen 28 | */ 29 | public class NextHistory implements Action { 30 | 31 | public String name() { 32 | return "next-history"; 33 | } 34 | 35 | @Override 36 | public void accept(InputProcessor inputProcessor) { 37 | int[] history = inputProcessor.buffer().history().getNextFetch(); 38 | if(history != null) { 39 | inputProcessor.buffer().replace(history); 40 | if(inputProcessor.editMode().mode().equals(EditMode.Mode.VI) && 41 | inputProcessor.editMode().status().equals(EditMode.Status.COMMAND)) 42 | inputProcessor.buffer().moveCursor(-history.length); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/PrevHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.action.Action; 24 | import org.aesh.readline.editing.EditMode; 25 | 26 | /** 27 | * @author Ståle W. Pedersen 28 | */ 29 | public class PrevHistory implements Action { 30 | @Override 31 | public String name() { 32 | return "previous-history"; 33 | } 34 | 35 | @Override 36 | public void accept(InputProcessor inputProcessor) { 37 | int[] history = inputProcessor.buffer().history().getPreviousFetch(); 38 | if(history != null) { 39 | inputProcessor.buffer().replace(history); 40 | if(inputProcessor.editMode().mode().equals(EditMode.Mode.VI) && 41 | inputProcessor.editMode().status().equals(EditMode.Status.COMMAND)) 42 | inputProcessor.buffer().moveCursor(-history.length); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/paste/PasteManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.paste; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * Keep track of edits for paste 27 | * 28 | * @author Ståle W. Pedersen 29 | */ 30 | public class PasteManager { 31 | 32 | private static final int PASTE_SIZE = 10; 33 | private final List pasteStack; 34 | 35 | public PasteManager() { 36 | pasteStack = new ArrayList<>(PASTE_SIZE); 37 | } 38 | 39 | public void addText(int[] buffer) { 40 | checkSize(); 41 | pasteStack.add(buffer); 42 | } 43 | 44 | private void checkSize() { 45 | if(pasteStack.size() >= PASTE_SIZE) { 46 | pasteStack.remove(0); 47 | } 48 | } 49 | 50 | public int[] get(int index) { 51 | if(index < pasteStack.size()) 52 | return pasteStack.get((pasteStack.size()-index-1)); 53 | else 54 | return pasteStack.get(0); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /terminal-telnet/src/test/java/org/aesh/terminal/telnet/tty/NettyBinaryTelnetTtyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.telnet.tty; 21 | 22 | import org.aesh.terminal.telnet.TelnetHandler; 23 | import org.aesh.terminal.telnet.TelnetServerRule; 24 | 25 | import java.io.Closeable; 26 | import java.util.function.Function; 27 | import java.util.function.Supplier; 28 | 29 | /** 30 | * @author Julien Viet 31 | */ 32 | public class NettyBinaryTelnetTtyTest extends TelnetTtyTestBase { 33 | 34 | public NettyBinaryTelnetTtyTest() { 35 | binary = true; 36 | } 37 | 38 | @Override 39 | protected Function, Closeable> serverFactory() { 40 | return TelnetServerRule.NETTY_SERVER; 41 | } 42 | 43 | @Override 44 | protected void assertThreading(Thread connThread, Thread schedulerThread) throws Exception { 45 | assertTrue(connThread.getName().startsWith("nioEventLoopGroup")); 46 | assertTrue(schedulerThread.getName().startsWith("nioEventLoopGroup")); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /terminal-telnet/src/test/java/org/aesh/terminal/telnet/tty/NettyAsciiTelnetTtyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.terminal.telnet.tty; 22 | 23 | 24 | import org.aesh.terminal.telnet.TelnetHandler; 25 | import org.aesh.terminal.telnet.TelnetServerRule; 26 | 27 | import java.io.Closeable; 28 | import java.util.function.Function; 29 | import java.util.function.Supplier; 30 | 31 | /** 32 | * @author Julien Viet 33 | */ 34 | public class NettyAsciiTelnetTtyTest extends TelnetTtyTestBase { 35 | 36 | public NettyAsciiTelnetTtyTest() { 37 | binary = false; 38 | } 39 | 40 | @Override 41 | protected Function, Closeable> serverFactory() { 42 | return TelnetServerRule.NETTY_SERVER; 43 | } 44 | 45 | @Override 46 | protected void assertThreading(Thread connThread, Thread schedulerThread) throws Exception { 47 | assertTrue(connThread.getName().startsWith("nioEventLoopGroup")); 48 | assertTrue(schedulerThread.getName().startsWith("nioEventLoopGroup")); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/ViEditingMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.action.Action; 23 | import org.aesh.readline.InputProcessor; 24 | import org.aesh.readline.editing.EditMode; 25 | import org.aesh.readline.editing.EditModeBuilder; 26 | 27 | /** 28 | * @author Ståle W. Pedersen 29 | */ 30 | public class ViEditingMode implements Action { 31 | 32 | ViEditingMode() { 33 | } 34 | 35 | @Override 36 | public String name() { 37 | return "vi-editing-mode"; 38 | } 39 | 40 | @Override 41 | public void accept(InputProcessor inputProcessor) { 42 | if(inputProcessor.editMode().mode() != EditMode.Mode.VI) 43 | inputProcessor.setEditMode(EditModeBuilder.builder(EditMode.Mode.VI).create()); 44 | if(inputProcessor.buffer().buffer().cursor() == 45 | inputProcessor.buffer().buffer().length()) 46 | inputProcessor.buffer().moveCursor(-1); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/Yank.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | public class Yank extends ChangeAction { 29 | 30 | Yank() { 31 | super(EditMode.Status.YANK); 32 | } 33 | 34 | @Override 35 | public String name() { 36 | return "yank"; 37 | } 38 | 39 | @Override 40 | public void accept(InputProcessor inputProcessor) { 41 | int[] pasteBuffer = inputProcessor.buffer().pasteManager().get(0); 42 | if(pasteBuffer != null) { 43 | 44 | if(inputProcessor.buffer().buffer().cursor() <= 45 | inputProcessor.buffer().buffer().length()) { 46 | inputProcessor.buffer().addActionToUndoStack(); 47 | inputProcessor.buffer().insert(pasteBuffer); 48 | inputProcessor.buffer().moveCursor(-1); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/MaskingReadlineTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline; 21 | 22 | import org.aesh.readline.terminal.Key; 23 | import org.aesh.readline.tty.terminal.TestConnection; 24 | import org.aesh.readline.util.Parser; 25 | import org.junit.Test; 26 | 27 | /** 28 | * @author Ståle W. Pedersen 29 | */ 30 | public class MaskingReadlineTest { 31 | 32 | @Test 33 | public void maskingTest() { 34 | TestConnection term = new TestConnection(new Prompt("", '\u0000')); 35 | 36 | term.read("MMyPassword"); 37 | term.assertOutputBuffer(""); 38 | term.read(Key.BACKSPACE); 39 | term.read(Key.ENTER); 40 | term.assertLine("MMyPasswor"); 41 | 42 | term = new TestConnection(new Prompt(Parser.toCodePoints("[foo] "), '%')); 43 | term.read("MMyPassword"); 44 | term.assertOutputBuffer("[foo] %%%%%%%%%%%"); 45 | term.clearOutputBuffer(); 46 | term.read(Key.BACKSPACE); 47 | term.read(Key.ENTER); 48 | term.assertLine("MMyPasswor"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /terminal-api/src/main/java/org/aesh/terminal/Terminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal; 21 | 22 | import java.io.Closeable; 23 | import java.io.InputStream; 24 | import java.io.OutputStream; 25 | import java.util.function.Consumer; 26 | import org.aesh.terminal.tty.Signal; 27 | import org.aesh.terminal.tty.Size; 28 | 29 | 30 | public interface Terminal extends Closeable { 31 | 32 | String getName(); 33 | 34 | // Signal support 35 | interface SignalHandler { 36 | void handle(Signal signal); 37 | } 38 | 39 | SignalHandler handle(Signal signal, SignalHandler handler); 40 | 41 | void raise(Signal signal); 42 | 43 | InputStream input(); 44 | 45 | OutputStream output(); 46 | 47 | //set echo attribute on terminal 48 | boolean echo(); 49 | 50 | boolean echo(boolean echo); 51 | 52 | Attributes getAttributes(); 53 | 54 | void setAttributes(Attributes attr); 55 | 56 | Size getSize(); 57 | 58 | // Infocmp capabilities 59 | Device device(); 60 | 61 | default Consumer getCodePointConsumer() { 62 | return null; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/EndOfFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Red Hat, Inc. and/or its affiliates. 3 | * 4 | * Licensed under the Eclipse Public License version 1.0, available at 5 | * http://www.eclipse.org/legal/epl-v10.html 6 | */ 7 | package org.aesh.readline.action.mappings; 8 | 9 | import org.aesh.readline.InputProcessor; 10 | import org.aesh.readline.ReadlineFlag; 11 | import org.aesh.readline.action.Action; 12 | import org.aesh.readline.terminal.Key; 13 | import org.aesh.terminal.utils.Config; 14 | 15 | /** 16 | * @author Ståle W. Pedersen 17 | */ 18 | public class EndOfFile implements Action { 19 | 20 | private int EOFCounter = 0; 21 | private int ignoreEOFSize = -1; 22 | 23 | @Override 24 | public String name() { 25 | return "eof"; 26 | } 27 | 28 | @Override 29 | public void accept(InputProcessor inputProcessor) { 30 | //always do this first 31 | if(ignoreEOFSize < 0) { 32 | ignoreEOFSize = inputProcessor.flags().getOrDefault(ReadlineFlag.IGNORE_EOF, 0); 33 | } 34 | //if buffer.length > 0 delete-char 35 | if(inputProcessor.buffer().buffer().length() > 0) { 36 | new DeleteChar().accept(inputProcessor); 37 | } 38 | else { 39 | //reset EOFCounter if prev key != ctrl-d 40 | if(EOFCounter > 0 && inputProcessor.editMode().prevKey() != null && 41 | inputProcessor.editMode().prevKey().getCodePointAt(0) != Key.CTRL_D.getFirstValue()) 42 | EOFCounter = 0; 43 | 44 | if(ignoreEOFSize > EOFCounter) 45 | EOFCounter++; 46 | else { 47 | //we got a eof, close the connection and call finish 48 | inputProcessor.connection().write(Config.getLineSeparator()); 49 | inputProcessor.connection().close(); 50 | inputProcessor.finish(null); 51 | } 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/netty/AsyncAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.netty; 21 | 22 | import java.util.function.Consumer; 23 | 24 | /** 25 | * @author Julien Viet 26 | */ 27 | public class AsyncAuth extends RuntimeException { 28 | 29 | private volatile Consumer listener; 30 | private volatile Boolean authed; 31 | 32 | public void setAuthed(boolean authed) { 33 | Consumer listener; 34 | synchronized (this) { 35 | if (this.authed != null) { 36 | return; 37 | } 38 | this.authed = authed; 39 | listener = this.listener; 40 | } 41 | if (listener != null) { 42 | listener.accept(authed); 43 | } 44 | } 45 | 46 | public void setListener(Consumer listener) { 47 | Boolean result; 48 | synchronized (this) { 49 | this.listener = listener; 50 | result = this.authed; 51 | } 52 | if (result != null) { 53 | listener.accept(result); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /terminal-telnet/src/main/java/org/aesh/terminal/telnet/TelnetHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.terminal.telnet; 22 | 23 | /** 24 | * The handler that defines the callbacks for a telnet connection. 25 | * 26 | * @author Julien Viet 27 | */ 28 | public class TelnetHandler { 29 | 30 | /** 31 | * The telnet connection opened. 32 | * 33 | * @param conn the connection 34 | */ 35 | protected void onOpen(TelnetConnection conn) {} 36 | 37 | /** 38 | * The telnet connection closed. 39 | */ 40 | protected void onClose() {} 41 | 42 | /** 43 | * Process data sent by the client. 44 | * 45 | * @param data the data 46 | */ 47 | protected void onData(byte[] data) {} 48 | 49 | protected void onSize(int width, int height) {} 50 | protected void onTerminalType(String terminalType) {} 51 | protected void onCommand(byte command) {} 52 | protected void onNAWS(boolean naws) {} 53 | protected void onEcho(boolean echo) {} 54 | protected void onSGA(boolean sga) {} 55 | protected void onSendBinary(boolean binary) { } 56 | protected void onReceiveBinary(boolean binary) { } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /terminal-api/src/main/java/org/aesh/terminal/tty/Point.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.tty; 21 | 22 | /** 23 | * @author Ståle W. Pedersen 24 | */ 25 | public final class Point { 26 | 27 | private final int x; 28 | private final int y; 29 | 30 | public Point(int x, int y) { 31 | this.x = x; 32 | this.y = y; 33 | } 34 | 35 | public int x() { 36 | return x; 37 | } 38 | 39 | public int y() { 40 | return y; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if (this == o) return true; 46 | if (o == null || getClass() != o.getClass()) return false; 47 | 48 | Point point = (Point) o; 49 | 50 | return x == point.x && y == point.y; 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | int result = x; 56 | result = 31 * result + y; 57 | return result; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "Point{" + 63 | "x=" + x + 64 | ", y=" + y + 65 | '}'; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/DeleteChar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.ConsoleBuffer; 23 | import org.aesh.readline.InputProcessor; 24 | import org.aesh.readline.action.Action; 25 | 26 | import java.util.Arrays; 27 | 28 | /** 29 | * @author Ståle W. Pedersen 30 | */ 31 | 32 | public class DeleteChar implements Action { 33 | 34 | public DeleteChar() { 35 | } 36 | 37 | @Override 38 | public String name() { 39 | return "delete-char"; 40 | } 41 | 42 | @Override 43 | public void accept(InputProcessor inputProcessor) { 44 | deleteNoMasking(inputProcessor.buffer()); 45 | } 46 | 47 | private void deleteNoMasking(ConsoleBuffer consoleBuffer) { 48 | int cursor = consoleBuffer.buffer().cursor(); 49 | int lineSize = consoleBuffer.buffer().length(); 50 | if(cursor < lineSize) { 51 | consoleBuffer.addActionToUndoStack(); 52 | consoleBuffer.pasteManager().addText(Arrays.copyOfRange(consoleBuffer.buffer().multiLine(), cursor, cursor+1)); 53 | consoleBuffer.delete(1); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/action/mappings/BackwardBigWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.action.mappings; 21 | 22 | import org.aesh.readline.InputProcessor; 23 | import org.aesh.readline.editing.EditMode; 24 | 25 | /** 26 | * @author Ståle W. Pedersen 27 | */ 28 | abstract class BackwardBigWord extends ChangeAction { 29 | 30 | BackwardBigWord(EditMode.Status status) { 31 | super(status); 32 | } 33 | 34 | BackwardBigWord(boolean viMode, EditMode.Status status) { 35 | super(viMode, status); 36 | } 37 | @Override 38 | public void accept(InputProcessor inputProcessor) { 39 | int cursor = inputProcessor.buffer().buffer().cursor(); 40 | String buffer = inputProcessor.buffer().buffer().asString(); 41 | 42 | if(cursor > buffer.length()) 43 | cursor = buffer.length()-1; 44 | 45 | //move back every potential space first 46 | while(cursor > 0 && isSpace(buffer.charAt(cursor-1))) 47 | cursor--; 48 | 49 | while(cursor > 0 && !isSpace(buffer.charAt(cursor-1))) 50 | cursor--; 51 | 52 | apply(cursor, inputProcessor); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/PasteReadlineTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline; 21 | 22 | import org.aesh.readline.tty.terminal.TestConnection; 23 | import org.aesh.terminal.utils.Config; 24 | import org.junit.Test; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | 28 | /** 29 | * @author Ståle W. Pedersen 30 | */ 31 | public class PasteReadlineTest { 32 | 33 | @Test 34 | public void paste() throws Exception { 35 | TestConnection connection = new TestConnection(); 36 | connection.read("connect" + Config.getLineSeparator() + 37 | "admin" + Config.getLineSeparator() + 38 | "admin!"); 39 | connection.assertLine("connect"); 40 | connection.readline(s -> { 41 | assertEquals("admin", s); 42 | connection.setPrompt(new Prompt("[password:] ",'\u0000')); 43 | }); 44 | connection.readline(); 45 | connection.assertBuffer("admin!"); 46 | assertEquals("[password:] ", connection.getOutputBuffer()); 47 | connection.read("234"+ Config.getLineSeparator()); 48 | connection.assertLine("admin!234"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/alias/Alias.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.alias; 21 | 22 | /** 23 | * Alias value object 24 | * 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class Alias implements Comparable { 28 | 29 | private final String name; 30 | private final String value; 31 | 32 | public Alias(String name, String value) { 33 | this.name = name; 34 | this.value = value; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public String getValue() { 42 | return value; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object o) { 47 | return (o instanceof Alias && ((Alias) o).getName().equals(getName())); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return 9320012; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return new StringBuilder(getName()).append("='") 58 | .append(getValue()).append("'").toString(); 59 | } 60 | 61 | @Override 62 | public int compareTo(Object o) { 63 | return getName().compareTo(((Alias )o ).getName()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/netty/Helper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.netty; 21 | 22 | import java.io.IOException; 23 | import java.io.InterruptedIOException; 24 | import java.util.concurrent.CompletableFuture; 25 | import java.util.function.Consumer; 26 | 27 | /** 28 | * @author Julien Viet 29 | */ 30 | class Helper { 31 | 32 | static IOException toIOException(Exception e) { 33 | if (e instanceof InterruptedException) { 34 | InterruptedIOException ioe = new InterruptedIOException(); 35 | ioe.initCause(e); 36 | return ioe; 37 | } else { 38 | return new IOException(e); 39 | } 40 | } 41 | 42 | public static Consumer startedHandler(CompletableFuture fut) { 43 | return err -> { 44 | if (err == null) { 45 | fut.complete(null); 46 | } else { 47 | fut.completeExceptionally(err); 48 | } 49 | }; 50 | } 51 | 52 | public static Consumer stoppedHandler(CompletableFuture fut) { 53 | return err -> { 54 | fut.complete(null); 55 | }; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/terminal/formatting/Color.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.formatting; 21 | 22 | /** 23 | * @author Ståle W. Pedersen 24 | */ 25 | public enum Color { 26 | 27 | BLACK(0), 28 | RED(1), 29 | GREEN(2), 30 | YELLOW(3), 31 | BLUE(4), 32 | MAGENTA(5), 33 | CYAN(6), 34 | WHITE(7), 35 | DEFAULT(9); 36 | 37 | private final int value; 38 | 39 | Color(int value) { 40 | this.value = value; 41 | } 42 | 43 | public int getValue() { 44 | return value; 45 | } 46 | 47 | public enum Intensity { 48 | NORMAL, 49 | BRIGHT; 50 | 51 | public int getValue(Type type) { 52 | if(this == NORMAL) { 53 | if(type == Type.FOREGROUND) 54 | return 3; 55 | else 56 | return 4; 57 | } 58 | else { 59 | if(type == Type.FOREGROUND) 60 | return 9; 61 | else 62 | return 10; 63 | } 64 | } 65 | } 66 | 67 | public enum Type { 68 | FOREGROUND, // 3 69 | BACKGROUND // 4 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /terminal-api/src/test/java/org/aesh/terminal/tty/TtyOutputModeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.tty; 21 | 22 | import org.junit.Test; 23 | 24 | import java.util.stream.IntStream; 25 | import java.util.stream.Stream; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | 29 | /** 30 | * @author Julien Viet 31 | */ 32 | public class TtyOutputModeTest { 33 | 34 | @Test 35 | public void testTranslateLFToCRLF() { 36 | assertOutput("a", "a"); 37 | assertOutput("\r\n", "\n"); 38 | assertOutput("a\r\n", "a\n"); 39 | assertOutput("\r\na", "\na"); 40 | assertOutput("a\r\nb\r\nc", "a\nb\nc"); 41 | } 42 | 43 | private void assertOutput(String expected, String actual) { 44 | Stream.Builder builder = Stream.builder(); 45 | TtyOutputMode out = new TtyOutputMode(builder); 46 | out.accept(toCodePoints(actual)); 47 | String result = fromCodePoints(builder.build().flatMapToInt(IntStream::of).toArray()); 48 | assertEquals(expected, result); 49 | } 50 | 51 | int[] toCodePoints(String s) { 52 | return s.codePoints().toArray(); 53 | } 54 | 55 | String fromCodePoints(int[] input) { 56 | return new String(input, 0, input.length); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /terminal-http/src/test/java/org/aesh/terminal/http/server/TaskStatusUpdateEventDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.http.server; 21 | 22 | import com.fasterxml.jackson.core.JsonParser; 23 | import com.fasterxml.jackson.core.JsonProcessingException; 24 | import com.fasterxml.jackson.databind.DeserializationContext; 25 | import com.fasterxml.jackson.databind.JsonDeserializer; 26 | import com.fasterxml.jackson.databind.JsonNode; 27 | import org.aesh.terminal.http.Status; 28 | 29 | import java.io.IOException; 30 | 31 | /** 32 | * @author Matej Lazar 33 | */ 34 | class TaskStatusUpdateEventDeserializer extends JsonDeserializer { 35 | @Override 36 | public TaskStatusUpdateEvent deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { 37 | JsonNode node = jp.getCodec().readTree(jp); 38 | String taskId = node.get("taskId").asText(); 39 | String oldStatus = node.get("oldStatus").asText(); 40 | String newStatus = node.get("newStatus").asText(); 41 | String context = node.get("context").asText(); 42 | 43 | return new TaskStatusUpdateEvent(taskId, Status.valueOf(oldStatus), Status.valueOf(newStatus), context); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /terminal-ssh/src/test/java/org/aesh/terminal/ssh/TestServiceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh; 21 | 22 | import org.aesh.terminal.ssh.netty.NettyIoAcceptor; 23 | import org.aesh.terminal.ssh.netty.NettyIoServiceFactory; 24 | import org.apache.sshd.common.FactoryManager; 25 | import org.apache.sshd.common.future.CloseFuture; 26 | import org.apache.sshd.common.io.IoAcceptor; 27 | import org.apache.sshd.common.io.IoHandler; 28 | import org.apache.sshd.common.io.nio2.Nio2ServiceFactory; 29 | 30 | import java.util.concurrent.ExecutorService; 31 | 32 | /** 33 | * @author Julien Viet 34 | */ 35 | public class TestServiceFactory extends Nio2ServiceFactory { 36 | 37 | private final NettyIoServiceFactory factory = new NettyIoServiceFactory(); 38 | 39 | public TestServiceFactory(FactoryManager factoryManager, ExecutorService service, boolean shutdownOnExit) { 40 | super(factoryManager, service, shutdownOnExit); 41 | } 42 | 43 | @Override 44 | public IoAcceptor createAcceptor(IoHandler handler) { 45 | return new NettyIoAcceptor(factory, handler); 46 | } 47 | 48 | @Override 49 | public CloseFuture close(boolean immediately) { 50 | factory.close(immediately); 51 | return super.close(immediately); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /terminal-http/src/test/java/org/aesh/terminal/http/utils/MockProcess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | package org.aesh.terminal.http.utils; 22 | 23 | /** 24 | * @author Matej Lazar 25 | */ 26 | public class MockProcess { 27 | 28 | public static final String WELCOME_MESSAGE = "Hi there! I'm a long running process."; 29 | public static final String MESSAGE = "Hello again!"; 30 | public static final String FINAL_MESSAGE = "I'm done."; 31 | 32 | /** 33 | * 34 | * @param args 1: Number of repeats. 2: Delay in ms. 35 | * @throws InterruptedException 36 | */ 37 | public static void main(String[] args) throws InterruptedException { 38 | 39 | int delay = 250; 40 | int repeat = 40; 41 | 42 | if (args.length >= 1) { 43 | repeat = Integer.parseInt(args[0]); 44 | } 45 | 46 | if (args.length >= 2) { 47 | delay = Integer.parseInt(args[1]); 48 | } 49 | 50 | System.out.println(WELCOME_MESSAGE); 51 | System.out.println("I'll write to stdout test message '" + MESSAGE + "' " + repeat + " times with " + delay + "ms delay."); 52 | for (int i = 0; i < repeat; i++) { 53 | System.out.println(i + " : " + MESSAGE); 54 | Thread.sleep(delay); 55 | } 56 | System.out.println(FINAL_MESSAGE); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /terminal-telnet/src/main/java/org/aesh/terminal/telnet/TelnetDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.telnet; 21 | 22 | import org.aesh.terminal.Device; 23 | import org.aesh.terminal.tty.Capability; 24 | 25 | import java.util.function.Consumer; 26 | 27 | /** 28 | * @author Ståle W. Pedersen 29 | */ 30 | public class TelnetDevice implements Device { 31 | 32 | private final String type; 33 | 34 | public TelnetDevice(String terminalType) { 35 | type = terminalType; 36 | } 37 | 38 | @Override 39 | public String type() { 40 | return type; 41 | } 42 | 43 | @Override 44 | public boolean getBooleanCapability(Capability capability) { 45 | return false; 46 | } 47 | 48 | @Override 49 | public Integer getNumericCapability(Capability capability) { 50 | return null; 51 | } 52 | 53 | @Override 54 | public String getStringCapability(Capability capability) { 55 | return null; 56 | } 57 | 58 | @Override 59 | public int[] getStringCapabilityAsInts(Capability capability) { 60 | return new int[0]; 61 | } 62 | 63 | @Override 64 | public boolean puts(Consumer output, Capability capability) { 65 | return false; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/undo/UndoManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.undo; 21 | 22 | import java.util.Stack; 23 | 24 | /** 25 | * @author Ståle W. Pedersen 26 | */ 27 | public class UndoManager { 28 | 29 | private static short UNDO_SIZE = 50; 30 | 31 | private Stack undoStack; 32 | private int counter; 33 | 34 | public UndoManager() { 35 | undoStack = new Stack<>(); 36 | undoStack.setSize(UNDO_SIZE); 37 | counter = 0; 38 | } 39 | 40 | public UndoAction getNext() { 41 | if(counter > 0) { 42 | counter--; 43 | return undoStack.pop(); 44 | } 45 | else 46 | return null; 47 | } 48 | 49 | public void addUndo(UndoAction u) { 50 | if(counter <= UNDO_SIZE) { 51 | counter++; 52 | undoStack.push(u); 53 | } 54 | else { 55 | undoStack.remove(UNDO_SIZE); 56 | undoStack.push(u); 57 | } 58 | 59 | } 60 | 61 | public void clear() { 62 | undoStack.clear(); 63 | counter = 0; 64 | } 65 | 66 | public boolean isEmpty() { 67 | return (counter == 0); 68 | } 69 | 70 | public int size() { 71 | return counter; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/util/IntArrayBuilder.java: -------------------------------------------------------------------------------- 1 | package org.aesh.readline.util; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * @author Ståle W. Pedersen 7 | */ 8 | public class IntArrayBuilder { 9 | 10 | private int[] data; 11 | private int size; 12 | 13 | public IntArrayBuilder() { 14 | data = new int[1]; 15 | size = 0; 16 | } 17 | 18 | public IntArrayBuilder(int size) { 19 | data = new int[size]; 20 | this.size = 0; 21 | } 22 | 23 | public IntArrayBuilder(int[] ints) { 24 | data = new int[ints.length]; 25 | System.arraycopy(ints, 0, data, 0, ints.length); 26 | size = data.length; 27 | } 28 | 29 | public IntArrayBuilder append(int[] str) { 30 | int len = str.length; 31 | ensureCapacityInternal(size + len); 32 | System.arraycopy(str, 0, data, size, len); 33 | size += len; 34 | return this; 35 | } 36 | 37 | public IntArrayBuilder append(int c) { 38 | ensureCapacityInternal(size + 1); 39 | data[size++] = c; 40 | return this; 41 | } 42 | 43 | public int[] toArray() { 44 | if(size == 0) 45 | return new int[]{}; 46 | else 47 | return Arrays.copyOf(data, size); 48 | } 49 | 50 | public int size() { 51 | return size; 52 | } 53 | 54 | public void deleteLastEntry() { 55 | if(size > 0) 56 | size--; 57 | } 58 | 59 | private void ensureCapacityInternal(int minimumCapacity) { 60 | // overflow-conscious code 61 | if (minimumCapacity - data.length > 0) 62 | expandCapacity(minimumCapacity); 63 | } 64 | 65 | private void expandCapacity(int minimumCapacity) { 66 | int newCapacity = data.length * 2 + 2; 67 | if (newCapacity - minimumCapacity < 0) 68 | newCapacity = minimumCapacity; 69 | if (newCapacity < 0) { 70 | if (minimumCapacity < 0) // overflow 71 | throw new OutOfMemoryError(); 72 | newCapacity = Integer.MAX_VALUE; 73 | } 74 | data = Arrays.copyOf(data, newCapacity); 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/util/TerminalUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.util; 21 | 22 | import org.aesh.readline.tty.terminal.TerminalConnection; 23 | import org.aesh.terminal.tty.Size; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * @author Ståle Pedersen 29 | */ 30 | public class TerminalUtil { 31 | 32 | public static int terminalWidth() { 33 | return terminalSize().getWidth(); 34 | } 35 | 36 | public static int terminalHeight() { 37 | return terminalSize().getHeight(); 38 | } 39 | 40 | public static Size terminalSize() { 41 | TerminalConnection connection = terminal(); 42 | if(connection != null) 43 | return connection.size(); 44 | else 45 | return new Size(-1,-1); 46 | } 47 | 48 | public static String terminalType() { 49 | TerminalConnection connection = terminal(); 50 | if(connection != null) 51 | return connection.device().type(); 52 | else 53 | return ""; 54 | } 55 | 56 | private static TerminalConnection terminal() { 57 | try { 58 | return new TerminalConnection(); 59 | } 60 | catch (IOException e) { 61 | return null; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /terminal-http/src/test/java/org/aesh/terminal/http/utils/Wait.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.http.utils; 21 | 22 | import java.time.LocalDateTime; 23 | import java.time.temporal.TemporalUnit; 24 | import java.util.concurrent.TimeoutException; 25 | import java.util.function.Supplier; 26 | 27 | /** 28 | * @author Matej Lazar 29 | */ 30 | public class Wait { 31 | 32 | public static void forCondition(Supplier evaluationSupplier, long timeout, TemporalUnit timeUnit) throws InterruptedException, TimeoutException { 33 | forCondition(evaluationSupplier, timeout, timeUnit, ""); 34 | } 35 | 36 | public static void forCondition(Supplier evaluationSupplier, long timeout, TemporalUnit timeUnit, String failedMessage) throws InterruptedException, TimeoutException { 37 | LocalDateTime started = LocalDateTime.now(); 38 | while (true) { 39 | if (started.plus(timeout, timeUnit).isBefore(LocalDateTime.now())) { 40 | throw new TimeoutException(failedMessage + " Reached timeout " + timeout + " " + timeUnit); 41 | } 42 | if (evaluationSupplier.get()) { 43 | break; 44 | } else { 45 | Thread.sleep(100); 46 | } 47 | } 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/util/ShortHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.util; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertTrue; 26 | 27 | /** 28 | * @author Ståle W. Pedersen 29 | */ 30 | public class ShortHelperTest { 31 | 32 | @Test 33 | public void testShortConverter() { 34 | testString("foo"); 35 | testString("as')(#/&!\"=#)dfae09fajfjdf aeufa3jas"); 36 | } 37 | 38 | private void testString(String input) { 39 | short[] shorts = ShortHelper.toShortPoints(input); 40 | int[] ints = Parser.toCodePoints(input); 41 | 42 | assertTrue(shorts.length == ints.length); 43 | 44 | for(int i=0; i < shorts.length; i++) { 45 | assertTrue(shorts[i] == ints[i]); 46 | } 47 | } 48 | 49 | @Test 50 | public void testFromShortToString() { 51 | fromShortToString("foo"); 52 | fromShortToString("as')(#/&!\"=#)dfae09fajfjdf aeufa3jas"); 53 | } 54 | 55 | private void fromShortToString(String input) { 56 | short[] shorts = ShortHelper.toShortPoints(input); 57 | String out = ShortHelper.fromShortPoints(shorts); 58 | 59 | assertEquals(input, out); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /terminal-http/src/test/java/org/aesh/terminal/http/tty/NettyWebsocketTtyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.http.tty; 21 | 22 | import org.aesh.terminal.Connection; 23 | import org.aesh.terminal.http.netty.NettyWebsocketTtyBootstrap; 24 | import org.junit.After; 25 | 26 | import java.util.concurrent.TimeUnit; 27 | import java.util.function.Consumer; 28 | 29 | /** 30 | * @author Julien Viet 31 | */ 32 | public class NettyWebsocketTtyTest extends WebsocketTtyTestBase { 33 | 34 | private NettyWebsocketTtyBootstrap bootstrap; 35 | 36 | @Override 37 | protected void server(Consumer onConnect) { 38 | if (bootstrap != null) { 39 | throw failure("Server already started"); 40 | } 41 | bootstrap = new NettyWebsocketTtyBootstrap().setHost("localhost").setPort(8080); 42 | try { 43 | bootstrap.start(onConnect).get(10, TimeUnit.SECONDS); 44 | } catch (Exception e) { 45 | throw failure(e); 46 | } 47 | } 48 | 49 | @After 50 | public void afterNettyWebsocket() throws Exception { 51 | if (bootstrap != null) { 52 | try { 53 | bootstrap.stop().get(10, TimeUnit.SECONDS); 54 | } catch (Exception e) { 55 | throw failure(e); 56 | } finally { 57 | bootstrap = null; 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/history/History.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.history; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * 26 | * @author Ståle W. Pedersen 27 | */ 28 | public abstract class History { 29 | 30 | private boolean enabled = true; 31 | 32 | public boolean isEnabled() { 33 | return enabled; 34 | } 35 | 36 | public void enable() { 37 | this.enabled = true; 38 | } 39 | 40 | public void disable(){ 41 | this.enabled = false; 42 | } 43 | 44 | public abstract void push(int[] entry); 45 | 46 | public abstract int[] find(int[] search); 47 | 48 | public abstract int[] get(int index); 49 | 50 | public abstract int size(); 51 | 52 | public abstract void setSearchDirection(SearchDirection direction); 53 | 54 | public abstract SearchDirection getSearchDirection(); 55 | 56 | public abstract int[] getNextFetch(); 57 | 58 | public abstract int[] getPreviousFetch(); 59 | 60 | public abstract int[] search(int[] search); 61 | 62 | public abstract void setCurrent(int[] line); 63 | 64 | public abstract int[] getCurrent(); 65 | 66 | public abstract List getAll(); 67 | 68 | public abstract void clear(); 69 | 70 | public abstract void stop(); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/netty/NettyIoServiceFactoryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh.netty; 21 | 22 | import io.netty.channel.EventLoopGroup; 23 | import org.apache.sshd.common.FactoryManager; 24 | import org.apache.sshd.common.io.IoServiceFactory; 25 | import org.apache.sshd.common.io.IoServiceFactoryFactory; 26 | 27 | /** 28 | * @author Julien Viet 29 | */ 30 | public class NettyIoServiceFactoryFactory implements IoServiceFactoryFactory { 31 | 32 | final EventLoopGroup eventLoopGroup; 33 | final NettyIoHandlerBridge handlerBridge; 34 | 35 | public NettyIoServiceFactoryFactory() { 36 | this.eventLoopGroup = null; 37 | this.handlerBridge = new NettyIoHandlerBridge(); 38 | } 39 | 40 | public NettyIoServiceFactoryFactory(EventLoopGroup eventLoopGroup) { 41 | this.eventLoopGroup = eventLoopGroup; 42 | this.handlerBridge = new NettyIoHandlerBridge(); 43 | } 44 | 45 | public NettyIoServiceFactoryFactory(EventLoopGroup eventLoopGroup, NettyIoHandlerBridge handlerBridge) { 46 | this.eventLoopGroup = eventLoopGroup; 47 | this.handlerBridge = handlerBridge; 48 | } 49 | 50 | @Override 51 | public IoServiceFactory create(FactoryManager manager) { 52 | return new NettyIoServiceFactory(eventLoopGroup, handlerBridge); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/example/SimpleTestExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.example; 21 | 22 | import org.aesh.readline.Readline; 23 | import org.aesh.readline.ReadlineBuilder; 24 | import org.aesh.readline.tty.terminal.TerminalConnection; 25 | 26 | import java.io.IOException; 27 | 28 | /** 29 | * Used by TestReadlineInSeparateProcess test 30 | * 31 | * @author Ståle W. Pedersen 32 | */ 33 | public class SimpleTestExample { 34 | 35 | public static void main(String... args) throws IOException { 36 | TerminalConnection connection = new TerminalConnection(); 37 | read(connection, ReadlineBuilder.builder().enableHistory(false).build(), ""); 38 | connection.openBlocking(); 39 | } 40 | 41 | private static void read(TerminalConnection connection, Readline readline, String prompt) { 42 | readline.readline(connection, prompt, input -> { 43 | if(input != null && input.equals("exit")) { 44 | connection.write("we're exiting\n"); 45 | connection.close(); 46 | } 47 | else { 48 | connection.write("=====> "+input+"\n"); 49 | //lets read until we get exit 50 | read(connection, readline, prompt); 51 | } 52 | }); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /terminal-api/src/main/java/org/aesh/terminal/tty/TtyOutputMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.tty; 21 | 22 | import java.util.function.Consumer; 23 | 24 | /** 25 | * @author Julien Viet 26 | */ 27 | public class TtyOutputMode implements Consumer { 28 | 29 | private final Consumer readHandler; 30 | 31 | public TtyOutputMode(Consumer readHandler) { 32 | this.readHandler = readHandler; 33 | } 34 | 35 | @Override 36 | public void accept(int[] data) { 37 | if (readHandler != null && data.length > 0) { 38 | int prev = 0; 39 | int ptr = 0; 40 | while (ptr < data.length) { 41 | // Simple implementation that works only on system that uses /n as line terminator 42 | // equivalent to 'stty onlcr' 43 | int cp = data[ptr]; 44 | if (cp == '\n') { 45 | if (ptr > prev) { 46 | sendChunk(data, prev, ptr); 47 | } 48 | readHandler.accept(new int[]{'\r','\n'}); 49 | prev = ++ptr; 50 | } else { 51 | ptr++; 52 | } 53 | } 54 | if (ptr > prev) { 55 | sendChunk(data, prev, ptr); 56 | } 57 | } 58 | } 59 | 60 | private void sendChunk(int[] data, int prev, int ptr) { 61 | int len = ptr - prev; 62 | int[] buf = new int[len]; 63 | System.arraycopy(data, prev, buf, 0, len); 64 | readHandler.accept(buf); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /readline/src/test/java/org/aesh/readline/completion/CompleteOperationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.completion; 21 | 22 | import org.junit.Test; 23 | 24 | import java.util.List; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | 28 | /** 29 | * @author Ståle W. Pedersen 30 | */ 31 | public class CompleteOperationTest { 32 | 33 | @Test 34 | public void testGetFormattedCompletionCandidates() { 35 | CompleteOperation co = new CompleteOperationImpl("ls foob", 6); 36 | co.addCompletionCandidate("foobar"); 37 | co.addCompletionCandidate("foobars"); 38 | co.setOffset(3); 39 | 40 | List formattedCandidates = co.getFormattedCompletionCandidates(); 41 | 42 | assertEquals("bar", formattedCandidates.get(0)); 43 | assertEquals("bars", formattedCandidates.get(1)); 44 | } 45 | 46 | @Test 47 | public void testRemoveEscapedSpacesFromCompletionCandidates() { 48 | CompleteOperation co = new CompleteOperationImpl("ls foob", 6); 49 | co.addCompletionCandidate("foo\\ bar"); 50 | co.addCompletionCandidate("foo\\ bars"); 51 | co.setOffset(3); 52 | 53 | co.removeEscapedSpacesFromCompletionCandidates(); 54 | 55 | assertEquals("foo bar", co.getCompletionCandidates().get(0).getCharacters()); 56 | assertEquals("foo bars", co.getCompletionCandidates().get(1).getCharacters()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /terminal-telnet/src/main/java/org/aesh/terminal/telnet/netty/NettyTelnetConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.telnet.netty; 21 | 22 | import io.netty.buffer.Unpooled; 23 | import io.netty.channel.ChannelFutureListener; 24 | import io.netty.channel.ChannelHandlerContext; 25 | import org.aesh.terminal.telnet.TelnetConnection; 26 | import org.aesh.terminal.telnet.TelnetHandler; 27 | 28 | import java.util.concurrent.TimeUnit; 29 | 30 | /** 31 | * @author Julien Viet 32 | */ 33 | public class NettyTelnetConnection extends TelnetConnection { 34 | 35 | final ChannelHandlerContext context; 36 | 37 | public NettyTelnetConnection(TelnetHandler handler, ChannelHandlerContext context) { 38 | super(handler); 39 | this.context = context; 40 | } 41 | 42 | @Override 43 | protected void execute(Runnable task) { 44 | context.channel().eventLoop().execute(task); 45 | } 46 | 47 | @Override 48 | protected void schedule(Runnable task, long delay, TimeUnit unit) { 49 | context.channel().eventLoop().schedule(task, delay, unit); 50 | } 51 | 52 | // Not properly synchronized, but ok for now 53 | @Override 54 | protected void send(byte[] data) { 55 | context.writeAndFlush(Unpooled.buffer().writeBytes(data)); 56 | } 57 | 58 | @Override 59 | protected void onClose() { 60 | super.onClose(); 61 | } 62 | 63 | @Override 64 | public void close() { 65 | context.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /readline/src/main/java/org/aesh/readline/terminal/impl/AbstractPosixTerminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.readline.terminal.impl; 21 | 22 | import org.aesh.terminal.Attributes; 23 | 24 | import java.io.IOError; 25 | import java.io.IOException; 26 | import org.aesh.terminal.tty.Size; 27 | 28 | public abstract class AbstractPosixTerminal extends AbstractTerminal { 29 | 30 | protected final Pty pty; 31 | protected final Attributes originalAttributes; 32 | 33 | public AbstractPosixTerminal(String name, String type, Pty pty) throws IOException { 34 | super(name, type); 35 | assert pty != null; 36 | this.pty = pty; 37 | this.originalAttributes = this.pty.getAttr(); 38 | } 39 | 40 | protected Pty getPty() { 41 | return pty; 42 | } 43 | 44 | public Attributes getAttributes() { 45 | try { 46 | return pty.getAttr(); 47 | } catch (IOException e) { 48 | throw new IOError(e); 49 | } 50 | } 51 | 52 | public void setAttributes(Attributes attr) { 53 | try { 54 | pty.setAttr(attr); 55 | } catch (IOException e) { 56 | throw new IOError(e); 57 | } 58 | } 59 | 60 | public Size getSize() { 61 | try { 62 | return pty.getSize(); 63 | } catch (IOException e) { 64 | throw new IOError(e); 65 | } 66 | } 67 | 68 | public void close() throws IOException { 69 | pty.setAttr(originalAttributes); 70 | pty.close(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /terminal-http/src/main/java/org/aesh/terminal/http/HttpDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.http; 21 | 22 | import org.aesh.terminal.BaseDevice; 23 | import org.aesh.terminal.tty.Capability; 24 | import org.aesh.terminal.utils.InfoCmp; 25 | 26 | import java.util.HashMap; 27 | import java.util.HashSet; 28 | import java.util.Map; 29 | import java.util.Set; 30 | 31 | /** 32 | * @author Ståle W. Pedersen 33 | */ 34 | public class HttpDevice extends BaseDevice { 35 | 36 | private final String type; 37 | private final Set bools; 38 | private final Map ints; 39 | private final Map strings; 40 | 41 | public HttpDevice(String type) { 42 | this.type = type; 43 | bools = new HashSet<>(); 44 | ints = new HashMap<>(); 45 | strings = new HashMap<>(); 46 | String data = InfoCmp.getDefaultInfoCmp(type); 47 | InfoCmp.parseInfoCmp(data, bools, ints, strings); 48 | } 49 | 50 | @Override 51 | public String type() { 52 | return type; 53 | } 54 | 55 | @Override 56 | public boolean getBooleanCapability(Capability capability) { 57 | return bools.contains(capability); 58 | } 59 | 60 | @Override 61 | public Integer getNumericCapability(Capability capability) { 62 | return ints.get(capability); 63 | } 64 | 65 | @Override 66 | public String getStringCapability(Capability capability) { 67 | return strings.get(capability); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /terminal-api/src/test/java/org/aesh/terminal/io/EncoderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.io; 21 | 22 | import org.junit.Test; 23 | 24 | import java.nio.charset.Charset; 25 | import java.util.ArrayList; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | 29 | /** 30 | * @author Ståle W. Pedersen 31 | */ 32 | public class EncoderTest { 33 | 34 | public void decodeEndcode(String incoming, String[] expected) { 35 | Charset charset = Charset.forName("UTF-8"); 36 | //ArrayList decodeResult = new ArrayList<>(); 37 | final ArrayList result = new ArrayList<>(); 38 | Decoder decoder = new Decoder(charset, event -> { 39 | result.add(event); 40 | }); 41 | 42 | final byte[] output = new byte[4]; 43 | Encoder encoder = new Encoder(charset, event -> { 44 | for(int i=0; i < event.length; i++) 45 | output[i] = event[i]; 46 | }); 47 | 48 | decoder.write(incoming.getBytes()); 49 | 50 | for(int i=0; i < expected.length; i++) { 51 | encoder.accept(result.get(i)); 52 | for(int j=0; j < expected[i].length(); j++) 53 | assertEquals(expected[i].getBytes()[j], output[j]); 54 | } 55 | } 56 | 57 | @Test 58 | public void testInputs() { 59 | decodeEndcode("foo", new String[] {"foo"}); 60 | decodeEndcode("foo bar!!??", new String[] {"foo ","bar!","!??"}); 61 | decodeEndcode("\r", new String[] {"\r"}); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /terminal-ssh/src/main/java/org/aesh/terminal/ssh/SSHDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors 4 | * as indicated by the @authors tag. All rights reserved. 5 | * See the copyright.txt in the distribution for a 6 | * full listing of individual contributors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package org.aesh.terminal.ssh; 21 | 22 | import org.aesh.terminal.BaseDevice; 23 | import org.aesh.terminal.tty.Capability; 24 | import org.aesh.terminal.utils.InfoCmp; 25 | 26 | import java.util.HashMap; 27 | import java.util.HashSet; 28 | import java.util.Map; 29 | import java.util.Set; 30 | 31 | /** 32 | * @author Ståle W. Pedersen 33 | */ 34 | public class SSHDevice extends BaseDevice { 35 | 36 | private final String type; 37 | private final Set bools; 38 | private final Map ints; 39 | private final Map strings; 40 | 41 | 42 | public SSHDevice(String type) { 43 | this.type = type; 44 | bools = new HashSet<>(); 45 | ints = new HashMap<>(); 46 | strings = new HashMap<>(); 47 | String data = InfoCmp.getDefaultInfoCmp(type); 48 | InfoCmp.parseInfoCmp(data, bools, ints, strings); 49 | } 50 | 51 | 52 | @Override 53 | public String type() { 54 | return type; 55 | } 56 | 57 | @Override 58 | public boolean getBooleanCapability(Capability capability) { 59 | return bools.contains(capability); 60 | } 61 | 62 | @Override 63 | public Integer getNumericCapability(Capability capability) { 64 | return ints.get(capability); 65 | } 66 | 67 | @Override 68 | public String getStringCapability(Capability capability) { 69 | return strings.get(capability); 70 | } 71 | 72 | } 73 | --------------------------------------------------------------------------------