001/*
002 * (C) Copyright 2006-2010 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu
016 */
017package org.nuxeo.shell.swing;
018
019import jline.ConsoleReader;
020import jline.Terminal;
021
022/**
023 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
024 */
025public class SwingTerminal extends Terminal {
026
027    protected Console console;
028
029    public SwingTerminal(Console console) {
030        this.console = console;
031    }
032
033    @Override
034    public boolean isSupported() {
035        return false;
036    }
037
038    @Override
039    public boolean getEcho() {
040        return true;
041    }
042
043    @Override
044    public boolean isANSISupported() {
045        return false;
046    }
047
048    @Override
049    public void initializeTerminal() {
050        // nothing we need to do (or can do) for windows.
051    }
052
053    @Override
054    public boolean isEchoEnabled() {
055        return true;
056    }
057
058    @Override
059    public void enableEcho() {
060    }
061
062    @Override
063    public void disableEcho() {
064    }
065
066    /**
067     * Always returng 80, since we can't access this info on Windows.
068     */
069    @Override
070    public int getTerminalWidth() {
071        return 80;
072    }
073
074    /**
075     * Always returng 24, since we can't access this info on Windows.
076     */
077    @Override
078    public int getTerminalHeight() {
079        return 80;
080    }
081
082    @Override
083    public void beforeReadLine(ConsoleReader reader, String prompt, Character mask) {
084        if (mask != null) {
085            console.setMask(mask);
086        }
087    }
088
089    @Override
090    public void afterReadLine(ConsoleReader reader, String prompt, Character mask) {
091        console.setMask(null);
092    }
093}