org.apache.sshd.common.channel.PtyMode Java Examples

The following examples show how to use org.apache.sshd.common.channel.PtyMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SshShellUtilsTest.java    From ssh-shell-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
void testFillAttributes() {
    Attributes attributes = new Attributes();
    Map<PtyMode, Integer> map = new HashMap<>();
    for (PtyMode value : PtyMode.values()) {
        map.put(value, 1);
    }
    SshShellUtils.fill(attributes, map);
    assertFalse(attributes.getControlChars().isEmpty());
}
 
Example #2
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final Environment env) throws IOException {
    String lcctype = env.getEnv().get("LC_CTYPE");
    if (lcctype != null) {
        charset = parseCharset(lcctype);
    }
    if (charset == null) {
        charset = defaultCharset;
    }
    env.addSignalListener(signal -> updateSize(env), EnumSet.of(org.apache.sshd.server.Signal.WINCH));
    updateSize(env);

    // Event handling
    int vintr = getControlChar(env, PtyMode.VINTR, 3);
    int veof = getControlChar(env, PtyMode.VEOF, 4);
    int vsusp = getControlChar(env, PtyMode.VSUSP, 26);

    device = new SSHDevice(env.getEnv().get("TERM"));
    attributes = SSHAttributesBuilder.builder().environment(env).build();
    eventDecoder = new EventDecoder(attributes);
    decoder = new Decoder(512, charset, eventDecoder);
    stdout = new TtyOutputMode(new Encoder(charset, out));
    conn = new SSHConnection();

    session.setDataReceiver(this);
    handler.accept(conn);
}
 
Example #3
Source File: TtyCommand.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final Environment env) throws IOException {
  String lcctype = env.getEnv().get("LC_CTYPE");
  if (lcctype != null) {
    charset = parseCharset(lcctype);
  }
  if (charset == null) {
    charset = defaultCharset;
  }
  env.addSignalListener(signal -> updateSize(env), EnumSet.of(org.apache.sshd.server.Signal.WINCH));
  updateSize(env);

  // Event handling
  int vintr = getControlChar(env, PtyMode.VINTR, 3);
  int vsusp = getControlChar(env, PtyMode.VSUSP, 26);
  int veof = getControlChar(env, PtyMode.VEOF, 4);

  //
  eventDecoder = new TtyEventDecoder(vintr, vsusp, veof);
  decoder = new BinaryDecoder(512, charset, eventDecoder);
  stdout = new TtyOutputMode(new BinaryEncoder(charset, out));
  term = env.getEnv().get("TERM");
  conn = new Connection();

  //
  session.setDataReceiver(this);
  handler.accept(conn);
}
 
Example #4
Source File: TtyCommand.java    From termd with Apache License 2.0 4 votes vote down vote up
private int getControlChar(Environment env, PtyMode key, int def) {
  Integer controlChar = env.getPtyModes().get(key);
  return controlChar != null ? controlChar : def;
}
 
Example #5
Source File: SshShellUtils.java    From ssh-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
/**
  * Fill attributes with given modes
  *
  * @param attr     attributes
  * @param ptyModes pty modes
  */
 public static void fill(Attributes attr, Map<PtyMode, Integer> ptyModes) {
     for (Map.Entry<PtyMode, Integer> e : ptyModes.entrySet()) {
         switch (e.getKey()) {
             case VINTR:
                 attr.setControlChar(Attributes.ControlChar.VINTR, e.getValue());
                 break;
             case VQUIT:
                 attr.setControlChar(Attributes.ControlChar.VQUIT, e.getValue());
                 break;
             case VERASE:
                 attr.setControlChar(Attributes.ControlChar.VERASE, e.getValue());
                 break;
             case VKILL:
                 attr.setControlChar(Attributes.ControlChar.VKILL, e.getValue());
                 break;
             case VEOF:
                 attr.setControlChar(Attributes.ControlChar.VEOF, e.getValue());
                 break;
             case VEOL:
                 attr.setControlChar(Attributes.ControlChar.VEOL, e.getValue());
                 break;
             case VEOL2:
                 attr.setControlChar(Attributes.ControlChar.VEOL2, e.getValue());
                 break;
             case VSTART:
                 attr.setControlChar(Attributes.ControlChar.VSTART, e.getValue());
                 break;
             case VSTOP:
                 attr.setControlChar(Attributes.ControlChar.VSTOP, e.getValue());
                 break;
             case VSUSP:
                 attr.setControlChar(Attributes.ControlChar.VSUSP, e.getValue());
                 break;
             case VDSUSP:
                 attr.setControlChar(Attributes.ControlChar.VDSUSP, e.getValue());
                 break;
             case VREPRINT:
                 attr.setControlChar(Attributes.ControlChar.VREPRINT, e.getValue());
                 break;
             case VWERASE:
                 attr.setControlChar(Attributes.ControlChar.VWERASE, e.getValue());
                 break;
             case VLNEXT:
                 attr.setControlChar(Attributes.ControlChar.VLNEXT, e.getValue());
                 break;
/*
case VFLUSH:
		attr.setControlChar(Attributes.ControlChar.VMIN, e.getValue());
		break;
case VSWTCH:
		attr.setControlChar(Attributes.ControlChar.VTIME, e.getValue());
		break;
*/
             case VSTATUS:
                 attr.setControlChar(Attributes.ControlChar.VSTATUS, e.getValue());
                 break;
             case VDISCARD:
                 attr.setControlChar(Attributes.ControlChar.VDISCARD, e.getValue());
                 break;
             case ECHO:
                 attr.setLocalFlag(Attributes.LocalFlag.ECHO, e.getValue() != 0);
                 break;
             case ICANON:
                 attr.setLocalFlag(Attributes.LocalFlag.ICANON, e.getValue() != 0);
                 break;
             case ISIG:
                 attr.setLocalFlag(Attributes.LocalFlag.ISIG, e.getValue() != 0);
                 break;
             case ICRNL:
                 attr.setInputFlag(Attributes.InputFlag.ICRNL, e.getValue() != 0);
                 break;
             case INLCR:
                 attr.setInputFlag(Attributes.InputFlag.INLCR, e.getValue() != 0);
                 break;
             case IGNCR:
                 attr.setInputFlag(Attributes.InputFlag.IGNCR, e.getValue() != 0);
                 break;
             case OCRNL:
                 attr.setOutputFlag(Attributes.OutputFlag.OCRNL, e.getValue() != 0);
                 break;
             case ONLCR:
                 attr.setOutputFlag(Attributes.OutputFlag.ONLCR, e.getValue() != 0);
                 break;
             case ONLRET:
                 attr.setOutputFlag(Attributes.OutputFlag.ONLRET, e.getValue() != 0);
                 break;
             case OPOST:
                 attr.setOutputFlag(Attributes.OutputFlag.OPOST, e.getValue() != 0);
                 break;
             default:
                 // nothing to do
         }
     }
 }
 
Example #6
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
private int getControlChar(Environment env, PtyMode key, int def) {
    Integer controlChar = env.getPtyModes().get(key);
    return controlChar != null ? controlChar : def;
}
 
Example #7
Source File: SSHAttributesBuilder.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
public Attributes build() {
    Attributes attr = new Attributes();
    for (Map.Entry<PtyMode, Integer> e : environment.getPtyModes().entrySet()) {
        switch (e.getKey()) {
            case VINTR:
                attr.setControlChar(Attributes.ControlChar.VINTR, e.getValue());
                break;
            case VQUIT:
                attr.setControlChar(Attributes.ControlChar.VQUIT, e.getValue());
                break;
            case VERASE:
                attr.setControlChar(Attributes.ControlChar.VERASE, e.getValue());
                break;
            case VKILL:
                attr.setControlChar(Attributes.ControlChar.VKILL, e.getValue());
                break;
            case VEOF:
                attr.setControlChar(Attributes.ControlChar.VEOF, e.getValue());
                break;
            case VEOL:
                attr.setControlChar(Attributes.ControlChar.VEOL, e.getValue());
                break;
            case VEOL2:
                attr.setControlChar(Attributes.ControlChar.VEOL2, e.getValue());
                break;
            case VSTART:
                attr.setControlChar(Attributes.ControlChar.VSTART, e.getValue());
                break;
            case VSTOP:
                attr.setControlChar(Attributes.ControlChar.VSTOP, e.getValue());
                break;
            case VSUSP:
                attr.setControlChar(Attributes.ControlChar.VSUSP, e.getValue());
                break;
            case VDSUSP:
                attr.setControlChar(Attributes.ControlChar.VDSUSP, e.getValue());
                break;
            case VREPRINT:
                attr.setControlChar(Attributes.ControlChar.VREPRINT, e.getValue());
                break;
            case VWERASE:
                attr.setControlChar(Attributes.ControlChar.VWERASE, e.getValue());
                break;
            case VLNEXT:
                attr.setControlChar(Attributes.ControlChar.VLNEXT, e.getValue());
                break;
            case VSTATUS:
                attr.setControlChar(Attributes.ControlChar.VSTATUS, e.getValue());
                break;
            case VDISCARD:
                attr.setControlChar(Attributes.ControlChar.VDISCARD, e.getValue());
                break;
            case ECHO:
                attr.setLocalFlag(Attributes.LocalFlag.ECHO, e.getValue() != 0);
                break;
            case ICANON:
                attr.setLocalFlag(Attributes.LocalFlag.ICANON, e.getValue() != 0);
                break;
            case ISIG:
                attr.setLocalFlag(Attributes.LocalFlag.ISIG, e.getValue() != 0);
                break;
            case ICRNL:
                attr.setInputFlag(Attributes.InputFlag.ICRNL, e.getValue() != 0);
                break;
            case INLCR:
                attr.setInputFlag(Attributes.InputFlag.INLCR, e.getValue() != 0);
                break;
            case IGNCR:
                attr.setInputFlag(Attributes.InputFlag.IGNCR, e.getValue() != 0);
                break;
            case OCRNL:
                attr.setOutputFlag(Attributes.OutputFlag.OCRNL, e.getValue() != 0);
                break;
            case ONLCR:
                attr.setOutputFlag(Attributes.OutputFlag.ONLCR, e.getValue() != 0);
                break;
            case ONLRET:
                attr.setOutputFlag(Attributes.OutputFlag.ONLRET, e.getValue() != 0);
                break;
            case OPOST:
                attr.setOutputFlag(Attributes.OutputFlag.OPOST, e.getValue() != 0);
                break;
        }
    }

    return attr;
}
 
Example #8
Source File: TtyCommand.java    From termd with Apache License 2.0 4 votes vote down vote up
private int getControlChar(Environment env, PtyMode key, int def) {
  Integer controlChar = env.getPtyModes().get(key);
  return controlChar != null ? controlChar : def;
}