001 /*
002 * Copyright (C) 2012 eXo Platform SAS.
003 *
004 * This is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU Lesser General Public License as
006 * published by the Free Software Foundation; either version 2.1 of
007 * the License, or (at your option) any later version.
008 *
009 * This software 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 * You should have received a copy of the GNU Lesser General Public
015 * License along with this software; if not, write to the Free
016 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
017 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
018 */
019 package org.crsh.ssh.term;
020
021 import org.apache.sshd.common.PtyMode;
022 import org.apache.sshd.server.Environment;
023
024 import java.util.logging.Level;
025 import java.util.logging.Logger;
026
027 public class SSHContext {
028
029 /** . */
030 private static final Logger log = Logger.getLogger(SSHContext.class.getName());
031
032 /** . */
033 public final int verase;
034
035 /** . */
036 private final Environment env;
037
038 public SSHContext(Environment env) {
039 if (env == null) {
040 throw new NullPointerException("No null env");
041 }
042
043 //
044 Integer verase = env.getPtyModes().get(PtyMode.VERASE);
045
046 //
047 this.env = env;
048 this.verase = verase != null ? verase : -1;
049 }
050
051 public int getWidth() {
052 String s = env.getEnv().get(Environment.ENV_COLUMNS);
053 int width = -1;
054 if (s != null) {
055 try {
056 width = Integer.parseInt(s);
057 }
058 catch (NumberFormatException e) {
059 log.log(Level.WARNING, "Could not parse ssh term width " + s);
060 }
061 }
062 return width;
063 }
064
065 public int getHeight() {
066 String s = env.getEnv().get(Environment.ENV_LINES);
067 int height = -1;
068 if (s != null) {
069 try {
070 height = Integer.parseInt(s);
071 }
072 catch (NumberFormatException e) {
073 log.log(Level.WARNING, "Could not parse ssh term height " + s);
074 }
075 }
076 return height;
077 }
078
079 public String getProperty(String key)
080 {
081 return env.getEnv().get(key);
082 }
083 }