Skip to content

Commit

Permalink
Possible exceptions when using gnu stty, fixes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Feb 27, 2017
1 parent b6b3136 commit 12219fa
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions terminal/src/main/java/org/jline/terminal/impl/ExecPty.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,30 @@ public Attributes getAttr() throws IOException {

@Override
public void setAttr(Attributes attr) throws IOException {
Attributes current = getAttr();
List<String> commands = getFlagsToSet(attr, getAttr());
if (!commands.isEmpty()) {
commands.add(0, OSUtils.STTY_COMMAND);
if (!system) {
commands.add(1, OSUtils.STTY_F_OPTION);
commands.add(2, getName());
}
try {
exec(system, commands.toArray(new String[commands.size()]));
} catch (IOException e) {
// Handle partial failures with GNU stty, see #97
if (e.toString().contains("unable to perform all requested operations")) {
commands = getFlagsToSet(attr, getAttr());
if (!commands.isEmpty()) {
throw new IOException("Could not set the following flags: " + String.join(", ", commands), e);
}
} else {
throw e;
}
}
}
}

protected List<String> getFlagsToSet(Attributes attr, Attributes current) {
List<String> commands = new ArrayList<>();
for (InputFlag flag : InputFlag.values()) {
if (attr.getInputFlag(flag) != current.getInputFlag(flag)) {
Expand Down Expand Up @@ -138,14 +161,7 @@ else if (v == 0) {
}
}
}
if (!commands.isEmpty()) {
commands.add(0, OSUtils.STTY_COMMAND);
if (!system) {
commands.add(1, OSUtils.STTY_F_OPTION);
commands.add(2, getName());
}
exec(system, commands.toArray(new String[commands.size()]));
}
return commands;
}

@Override
Expand Down

0 comments on commit 12219fa

Please sign in to comment.