001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.shell.swing;
020
021import jline.ConsoleReader;
022import jline.Terminal;
023
024/**
025 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
026 */
027public class SwingTerminal extends Terminal {
028
029    protected Console console;
030
031    public SwingTerminal(Console console) {
032        this.console = console;
033    }
034
035    @Override
036    public boolean isSupported() {
037        return false;
038    }
039
040    @Override
041    public boolean getEcho() {
042        return true;
043    }
044
045    @Override
046    public boolean isANSISupported() {
047        return false;
048    }
049
050    @Override
051    public void initializeTerminal() {
052        // nothing we need to do (or can do) for windows.
053    }
054
055    @Override
056    public boolean isEchoEnabled() {
057        return true;
058    }
059
060    @Override
061    public void enableEcho() {
062    }
063
064    @Override
065    public void disableEcho() {
066    }
067
068    /**
069     * Always returng 80, since we can't access this info on Windows.
070     */
071    @Override
072    public int getTerminalWidth() {
073        return 80;
074    }
075
076    /**
077     * Always returng 24, since we can't access this info on Windows.
078     */
079    @Override
080    public int getTerminalHeight() {
081        return 80;
082    }
083
084    @Override
085    public void beforeReadLine(ConsoleReader reader, String prompt, Character mask) {
086        if (mask != null) {
087            console.setMask(mask);
088        }
089    }
090
091    @Override
092    public void afterReadLine(ConsoleReader reader, String prompt, Character mask) {
093        console.setMask(null);
094    }
095}