Package org.jboss.aesh.console.settings

Examples of org.jboss.aesh.console.settings.SettingsBuilder


        if(!settings.getInputrc().isFile()) {
            if(settings.isLogging())
                logger.info("Error while parsing: "+settings.getInputrc().getAbsolutePath()+" couldn't find file.");
            return settings;
        }
        SettingsBuilder builder = new SettingsBuilder(settings);

        Pattern variablePattern = Pattern.compile("^set\\s+(\\S+)\\s+(\\S+)$");
        Pattern commentPattern = Pattern.compile("^#.*");
        //Pattern keyNamePattern = Pattern.compile("^\\b:\\s+\\b");
        Pattern keyQuoteNamePattern = Pattern.compile("(^\"\\\\\\S+)(\":\\s+)(\\S+)");
        Pattern keyNamePattern = Pattern.compile("(^\\S+)(:\\s+)(\\S+)");
        Pattern keySeqPattern = Pattern.compile("^\"keyseq:\\s+\\b");
        Pattern startConstructs = Pattern.compile("^\\$if");
        Pattern endConstructs = Pattern.compile("^\\$endif");

        Pattern keyOperationPattern = Pattern.compile("(^\\\"\\\\M-\\[D:)(\\s+)(\\S+)");

        BufferedReader reader =
                new BufferedReader( new FileReader(settings.getInputrc()));

        String line;
        boolean constructMode = false;
        while( (line = reader.readLine()) != null) {
            if(line.trim().length() < 1)
                continue;
            //first check if its a comment
            if(commentPattern.matcher(line).matches())
                continue;

            if(startConstructs.matcher(line).matches()) {
                constructMode = true;
                continue;
            }
            else if(endConstructs.matcher(line).matches()) {
                constructMode = false;
                continue;
            }

            if(constructMode) {

            }
            //everything other than if/else
            else {
                // variable settings
                Matcher variableMatcher = variablePattern.matcher(line);
                if(variableMatcher.matches()) {
                    parseVariables(variableMatcher.group(1), variableMatcher.group(2), builder);
                }
                //TODO: currently the inputrc parser is posix only
                if(Config.isOSPOSIXCompatible()) {
                    Matcher keyQuoteMatcher = keyQuoteNamePattern.matcher(line);
                    if(keyQuoteMatcher.matches()) {
                        builder.create().getOperationManager().addOperationIgnoreWorkingMode(
                                KeyMapper.mapQuoteKeys(keyQuoteMatcher.group(1),
                                        keyQuoteMatcher.group(3)));
                    }
                    else {
                        Matcher keyMatcher = keyNamePattern.matcher(line);
                        if(keyMatcher.matches()) {
                            builder.create().getOperationManager().addOperationIgnoreWorkingMode(KeyMapper.mapKeys(keyMatcher.group(1), keyMatcher.group(3)));
                        }
                    }
                }
            }

        }

        //finally close
        reader.close();

        return builder.create();
    }
View Full Code Here


                        ", only: "+DISABLE_COMPLETION.getValues());
        }
    }

    protected static Settings readRuntimeProperties(Settings settings) {
       SettingsBuilder builder = new SettingsBuilder(settings);
        try {
            String term = System.getProperty("aesh.terminal");
            if(term != null && term.length() > 0) {
                builder.terminal((Terminal) settings.getClass().getClassLoader().loadClass(term).newInstance());
            }
            String editMode = System.getProperty("aesh.editmode");
            if(editMode != null && editMode.length() > 0) {
                if(editMode.equalsIgnoreCase("VI"))
                    builder.mode(Mode.VI);
                else if(editMode.equalsIgnoreCase("EMACS"))
                    builder.mode(Mode.EMACS);
            }
            String readInputrc = System.getProperty("aesh.readinputrc");
            if(readInputrc != null && readInputrc.length() > 0)
                if(readInputrc.equalsIgnoreCase("true") ||
                        readInputrc.equalsIgnoreCase("false"))
                    builder.readInputrc(Boolean.parseBoolean(readInputrc));

            String inputrc = System.getProperty("aesh.inputrc");
            if(inputrc != null && inputrc.length() > 0)
                if(new File(inputrc).isFile())
                    builder.inputrc(new File(inputrc));

            String historyFile = System.getProperty("aesh.historyfile");
            if(historyFile != null && historyFile.length() > 0)
                if(new File(historyFile).isFile())
                    builder.historyFile(new File(historyFile));

            String historyPersistent = System.getProperty("aesh.historypersistent");
            if(historyPersistent != null && historyPersistent.length() > 0)
                if(historyPersistent.equalsIgnoreCase("true") ||
                        historyPersistent.equalsIgnoreCase("false"))
                    builder.persistHistory(Boolean.parseBoolean(historyPersistent));

            String historyDisabled = System.getProperty("aesh.historydisabled");
            if(historyDisabled != null && historyDisabled.length() > 0)
                if(historyDisabled.equalsIgnoreCase("true") ||
                        historyDisabled.equalsIgnoreCase("false"))
                    builder.disableHistory(Boolean.parseBoolean(historyDisabled));

            String historySize = System.getProperty("aesh.historysize");
            if(historySize != null && historySize.length() > 0)
                builder.historySize(Integer.parseInt(historySize));

            String doLogging = System.getProperty("aesh.logging");
            if(doLogging != null && doLogging.length() > 0)
                if(doLogging.equalsIgnoreCase("true") ||
                        doLogging.equalsIgnoreCase("false"))
                    builder.logging(Boolean.parseBoolean(doLogging));

            String logFile = System.getProperty("aesh.logfile");
            if(logFile != null && logFile.length() > 0)
                builder.logfile(logFile);

            String disableCompletion = System.getProperty("aesh.disablecompletion");
            if(disableCompletion != null && disableCompletion.length() > 0)
                if(disableCompletion.equalsIgnoreCase("true") ||
                        disableCompletion.equalsIgnoreCase("false"))
                    builder.disableCompletion(Boolean.parseBoolean(disableCompletion));

          }
        catch (ClassNotFoundException e) {
            if(settings.isLogging())
                logger.log(Level.SEVERE, "Fail while finding class: ", e);
        } catch (InstantiationException e) {
            if(settings.isLogging())
                logger.log(Level.SEVERE, "Fail while instantiating class: ", e);
        } catch (IllegalAccessException e) {
            if(settings.isLogging())
                logger.log(Level.SEVERE, "Fail while accessing class: ", e);
        }

        return builder.create();
    }
View Full Code Here

      public Settings getSettings()
      {
         try
         {
            inputStream = new PipedInputStream(stdin);
            settings = new SettingsBuilder()
                     .inputStream(inputStream)
                     .outputStream(new PrintStream(stdout))
                     .outputStreamError(new PrintStream(stderr))
                     .name("test")
                     .logging(true)
View Full Code Here

      File history = new File(forgeHome, "history");
      File alias = new File(forgeHome, "alias");
      File export = new File(forgeHome, "export");
      final ForgeCommandRegistry registry =
               new ForgeCommandRegistry(this, addonRegistry);
      Settings newSettings = new SettingsBuilder(settings)
               .historyFile(history)
               .aliasFile(alias)
               .exportFile(export)
               .interruptHook(new ForgeInterruptHook(registry)).create();
      this.console = new AeshConsoleBuilder()
View Full Code Here

TOP

Related Classes of org.jboss.aesh.console.settings.SettingsBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.