Code Monkey home page Code Monkey logo

Comments (14)

cronvel avatar cronvel commented on August 20, 2024

Customization is possible, but not syntax highlighting, i.e. you can set the style and color for the whole text, but not per character.

It is an interesting feature, but there is no plan for that ATM.

Can you describe me your use case? (more background)

from terminal-kit.

yann-stepienik-cko avatar yann-stepienik-cko commented on August 20, 2024

Sure : the terminal command expect arguments / filenames, and I would like to :

  • Highlight typos (unexisting arguments)
  • underline filenames
  • (EVENTUALLY) write a preview of what pressing TAB would autocomplete too, in a light color on the right of the cursor like this :

screen shot 2017-03-02 at 18 00 21

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

Any idea about the eventual API?

from terminal-kit.

yann-stepienik-cko avatar yann-stepienik-cko commented on August 20, 2024

Yep sure I'm thinking it would look something like this I guess :

{
   format : function(previous (all previous token), current, term)
}

the function would be called per-token (ex : git clone http://.... would be 3 token : git, clone and the url) and each token would be returned as so :

function (previous, current, term) {
    if(!exists(current)) {
       return term.red("current")
    } 
    else if(previous == "git clone") { 
        return checkURL(current) ? term.underline(current) : term.red(current)
    }
    else {
         return term.green(current)
    }
}

For the placeholder-prediction, I would say that when the autoCompleter function return an array the first element gets displayed as "placeholder" like in the screen, if it returns a string it gets displayed.

What do you think?

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

The API looks good to me, however it would be a nightmare to implement it ^^

Mostly because of the string length management (how many columns and lines are covered by the input field, and so on).
Terminals are really old things that have not evolved a bit for decades, they lack critical features.

If one day I implement this feature, I will surely do it using the Terminal-kit ScreenBuffer, or a TextBuffer/ScreenBuffer combo. But the API will certainly be less user-friendly.

Do you intend to write a kind of next gen Bash?

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

Ok, I will give it a try...

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

Ok I was overestimating the difficulty, in fact it was fairly straightforward to implement.

But I'm still unsure about the API.
Maybe it will land tomorrow or monday on master, once I'm satisfied.

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

Ok, it's done: token hilighting (color, style) and the auto-completion preview.
It landed on version 0.27.1.

The doc is not updated ATM (will do it in few days), but you can look at the sample file sample/input-field-shell-test.js, or look at this extract:

var term = require( 'terminal-kit' ).terminal ;

term( '> ' ) ;

var autoComplete = [
    'dnf install' ,
    'dnf install nodejs' ,
    'dnf search' ,
    'sudo' ,
    'sudo dnf install' ,
    'sudo dnf install nodejs' ,
    'sudo dnf search' ,
] ;

term.inputField(
    {
        autoComplete: autoComplete ,
        autoCompleteHint: true ,
        tokenHook: function( token , isEndOfInput , previousTokens , term , config ) {
            var previousText = previousTokens.join( ' ' ) ;
            
            switch ( token )
            {
                case 'sudo' :
                    config.style = term.red ;
                    return previousTokens.length ? null : term.bold.red ;
                case 'dnf' :
                    return previousText === '' || previousText === 'sudo' ? term.brightMagenta : null ;
                case 'install' :
                    config.style = term.brightBlue ;
                    config.hintStyle = term.brightBlack.italic ;
                    return previousText === 'dnf' || previousText === 'sudo dnf' ? term.brightYellow : null ;
                case 'search' :
                    config.style = term.brightBlue ;
                    return previousText === 'dnf' || previousText === 'sudo dnf' ? term.brightCyan : null ;
            }
        }
    } ,
    function( error , input ) {

        term.green( "\nYour command is: '%s'\n" , input ) ;
        process.exit() ;
    }
) ;

The autoCompleteHint option is the auto-completion preview. You can customize its style with the hintStyle option.

from terminal-kit.

azukaar avatar azukaar commented on August 20, 2024

Hey @cronvel
Really nice work, I'll give it a try ASAP, thanks !
Yes this is what I'm writing (I'm lacking a terminal alternative that I could use on all my computers no matter the OS)

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

As of v 0.28.0, I have changed the tokenHook function's argument to ( token , isEndOfInput , previousTokens , term , config ).

I edited the previous example.

  • isEndOfInput boolean true if this is the last token and if it ends the input string (e.g. it is possible for the last token to be followed by some blank char, in that case isEndOfInput would be false)

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

@azukaar @yann-stepienik-cko If you are interested, I made a small shell prototype to test all those features: ngsh.

When you will start working on your shell, I would appreciate to have a look at it! Drop me comment ;)

from terminal-kit.

azukaar avatar azukaar commented on August 20, 2024

Hey @cronvel I did a bit more work on the project I'll show it to you, but I just realise that the whole purpose of the project was kind of defeated because of #16, do you think this issue is patch-able, or do I need to not use inputField ?

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

@azukaar @yann-stepienik-cko If you want to target Windows platform, that's certainly a problem, with or without .inputField(), with or without Terminal-Kit.
Windows terminals just lack critical features for that.

FYI readline (built-in support in Node.js) usually manages to work well on those impossible terminals at the cost of really complex (and awful) hacks. However, readline does not allow you syntax hilighting.

from terminal-kit.

yann-stepienik-cko avatar yann-stepienik-cko commented on August 20, 2024

@cronvel Will look at it more in details this week end

from terminal-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.