mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use console charset for reading/writing to stdin/out
This commit is contained in:
parent
425e451237
commit
e03c48e0ae
4 changed files with 9 additions and 5 deletions
|
@ -46,7 +46,6 @@ import java.io.BufferedWriter;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static net.sourceforge.argparse4j.DefaultSettings.VERSION_0_9_0_DEFAULT_SETTINGS;
|
||||
|
||||
|
@ -123,7 +122,7 @@ public class App {
|
|||
var outputType = outputTypeInput == null
|
||||
? command.getSupportedOutputTypes().stream().findFirst().orElse(null)
|
||||
: outputTypeInput;
|
||||
var writer = new BufferedWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
|
||||
var writer = new BufferedWriter(new OutputStreamWriter(System.out, IOUtils.getConsoleCharset()));
|
||||
var outputWriter = outputType == null
|
||||
? null
|
||||
: outputType == OutputType.JSON ? new JsonWriterImpl(writer) : new PlainTextWriterImpl(writer);
|
||||
|
|
|
@ -48,7 +48,8 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
|
|||
m.setIgnoreAttachments(ignoreAttachments);
|
||||
|
||||
final var jsonOutputWriter = (JsonWriter) outputWriter;
|
||||
final Supplier<String> lineSupplier = IOUtils.getLineSupplier(new InputStreamReader(System.in));
|
||||
final Supplier<String> lineSupplier = IOUtils.getLineSupplier(new InputStreamReader(System.in,
|
||||
IOUtils.getConsoleCharset()));
|
||||
|
||||
final var handler = new SignalJsonRpcDispatcherHandler(jsonOutputWriter, lineSupplier, false);
|
||||
handler.handleConnection(m);
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
@ -120,7 +119,7 @@ public class SendCommand implements JsonRpcLocalCommand {
|
|||
if (readMessageFromStdin || (messageText == null && sticker == null)) {
|
||||
logger.debug("Reading message from stdin...");
|
||||
try {
|
||||
messageText = IOUtils.readAll(System.in, Charset.defaultCharset());
|
||||
messageText = IOUtils.readAll(System.in, IOUtils.getConsoleCharset());
|
||||
} catch (IOException e) {
|
||||
throw new UserErrorException("Failed to read message from stdin: " + e.getMessage());
|
||||
}
|
||||
|
|
|
@ -39,6 +39,11 @@ public class IOUtils {
|
|||
private IOUtils() {
|
||||
}
|
||||
|
||||
public static Charset getConsoleCharset() {
|
||||
final var console = System.console();
|
||||
return console == null ? Charset.defaultCharset() : console.charset();
|
||||
}
|
||||
|
||||
public static String readAll(InputStream in, Charset charset) throws IOException {
|
||||
var output = new StringWriter();
|
||||
var buffer = new byte[4096];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue