/* * libbrlapi - A library providing access to braille terminals for applications. * * Copyright (C) 2006-2021 by * Samuel Thibault * Sébastien Hinderer * * libbrlapi comes with ABSOLUTELY NO WARRANTY. * * This is free software, placed under the terms of the * GNU Lesser General Public License, as published by the Free Software * Foundation; either version 2.1 of the License, or (at your option) any * later version. Please see the file LICENSE-LGPL for details. * * Web Page: http://brltty.app/ * * This software is maintained by Dave Mielke . */ package org.a11y.brlapi.clients; import org.a11y.brlapi.*; import java.io.InterruptedIOException; import java.util.concurrent.TimeoutException; public class EchoClient extends Client { private boolean echoDriverKeys = false; private boolean echoNames = false; public final static int MINIMUM_READ_COUNT = 1; public final static int DEFAULT_READ_COUNT = 10; public final static String NO_TIMEOUT = "none"; public final static int FOREVER_READ_TIMEOUT = 0; public final static int MINIMUM_READ_TIMEOUT = 1; public final static int DEFAULT_READ_TIMEOUT = 10; private int readCount = DEFAULT_READ_COUNT; private final OperandUsage readCountUsage = new OperandUsage("read count") .setDefault(readCount) .setRangeMinimum(MINIMUM_READ_COUNT) ; private int readTimeout = DEFAULT_READ_TIMEOUT; private final OperandUsage readTimeoutUsage = new OperandUsage("read timeout") .setDefault(readTimeout) .setRangeMinimum(MINIMUM_READ_TIMEOUT) .setRangeUnits("seconds") .setRangeComment("readKeyWithTimeout is used") .addWord(NO_TIMEOUT, FOREVER_READ_TIMEOUT, "readKey is used") ; public EchoClient (String... arguments) { super(arguments); addRepeatingParameter("tty"); addOption("commands", (operands) -> { echoDriverKeys = false; } ); addOption("keys", (operands) -> { echoDriverKeys = true; } ); addOption("values", (operands) -> { echoNames = false; } ); addOption("names", (operands) -> { echoNames = true; } ); addOption("reads", (operands) -> { readCount = Parse.asInt( readCountUsage.getOperandDescription(), operands[0], MINIMUM_READ_COUNT ); }, "count" ); addOption("timeout", (operands) -> { String operand = operands[0]; if (Strings.isAbbreviation(NO_TIMEOUT, operand)) { readTimeout = FOREVER_READ_TIMEOUT; } else { readTimeout = Parse.asInt( readTimeoutUsage.getOperandDescription(), operand, MINIMUM_READ_TIMEOUT ); } }, "seconds" ); } @Override protected final void extendUsageSummary (StringBuilder usage) { super.extendUsageSummary(usage); readCountUsage.appendTo(usage); readTimeoutUsage.appendTo(usage); } private int[] ttyPath = null; @Override protected void processParameters (String[] parameters) throws SyntaxException { int count = parameters.length; ttyPath = new int[count]; for (int i=0; i 0) { builder.append( String.format( " Arg:%04X(%d)", argument, argument ) ); } } { String[] flags = keycode.getFlagNames(); if (flags != null) { int count = flags.length; boolean first = true; for (int index=0; index { show(con, String.format( "press keys (timeout is %d seconds)", readTimeout ) ); while (readCount-- > 0) { long code; try { if (readTimeout == FOREVER_READ_TIMEOUT) { code = con.readKey(); } else { code = con.readKeyWithTimeout((readTimeout * 1000)); } } catch (InterruptedIOException exception) { continue; } catch (TimeoutException exception) { break; } show(con, toString(con, code)); } }, ttyPath ); } }