Skip to content

Commit

Permalink
add: writeLine method
Browse files Browse the repository at this point in the history
  • Loading branch information
hsshss committed Oct 25, 2020
1 parent ac78c51 commit 16f0cd8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ A simple telnet server written in Java. <br />
srv.registerCommand("echo", new Command() {
@Override
public void execute(String name, String argument, EasyTerminal terminal) throws IOException {
terminal.write(argument);
terminal.write("\r\n");
terminal.writeLine(argument);
terminal.flush();
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/net/nbug/hexprobe/server/telnet/EasyShellServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void execute(String name, String argument, EasyTerminal terminal) throws
registerCommand("help", new Command() {
@Override
public void execute(String name, String argument, EasyTerminal terminal) throws IOException {
terminal.write(StringUtils.join(" ", commands.keySet()) + "\r\n");
terminal.writeLine(StringUtils.join(" ", commands.keySet()));
terminal.flush();
}
});
Expand All @@ -39,10 +39,10 @@ public void execute(String name, String argument, EasyTerminal terminal) throws
public void execute(String name, String argument, EasyTerminal terminal) throws IOException {
if (terminal.isLogMode()) {
terminal.setLogMode(false);
terminal.write("LogMode disabled.\r\n");
terminal.writeLine("LogMode disabled.");
} else {
terminal.setLogMode(true);
terminal.write("LogMode enabled.\r\n");
terminal.writeLine("LogMode enabled.");
}
terminal.flush();
}
Expand Down Expand Up @@ -88,14 +88,14 @@ public void OnCommandLine(EasyTerminal terminal, String commandLine) throws IOEx
} else if (name.isEmpty()) {
// Do nothing
} else {
terminal.write("Command not found.\r\n");
terminal.writeLine("Command not found.");
terminal.flush();
}
} catch (IOException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
terminal.write("Error: " + e.toString() + "\r\n");
terminal.writeLine("Error: " + e.toString());
terminal.flush();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/net/nbug/hexprobe/server/telnet/EasyTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
public interface EasyTerminal {
void write(String s) throws IOException;
void writeLine(String s) throws IOException;
void flush() throws IOException;
void close() throws IOException;
InputStream getInputStream();
Expand Down
2 changes: 1 addition & 1 deletion src/net/nbug/hexprobe/server/telnet/TelnetTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void onClearScreen() throws IOException {
} else {
switch (b) {
case CR:
terminal.write("\r\n");
terminal.writeLine("");
terminal.flush();

if (onCommandLineListener != null) {
Expand Down
6 changes: 6 additions & 0 deletions src/net/nbug/hexprobe/server/telnet/VT100Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public void write(String s) throws IOException {
}
}

@Override
public void writeLine(String s) throws IOException {
write(s);
write("\r\n");
}

@Override
public void flush() throws IOException {
out.flush();
Expand Down

0 comments on commit 16f0cd8

Please sign in to comment.