Comments (14)
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.
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 :
from terminal-kit.
Any idea about the eventual API?
from terminal-kit.
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.
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.
Ok, I will give it a try...
from terminal-kit.
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.
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.
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.
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.
@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.
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.
@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.
@cronvel Will look at it more in details this week end
from terminal-kit.
Related Issues (20)
- Word/Line wrap ERROR when x,y,width or height of TextBox are non integers
- Unable to draw the correct image in vscode dark-mode terminal!
- Can't run after packed with pkg HOT 3
- Cannot input after using term.inputField() HOT 4
- Issue: Terminal stuck in while-loop when initating another terminal with stdin/stdout
- Form control event and validation
- form render issue - hide/show control
- Erase Everything - How? HOT 1
- Possible EventEmitter memory leak
- Multiple Documents in Same Terminal Screen
- support for fonts HOT 1
- term.table does not work in Azure pipeline HOT 6
- term.table does not work in Azure pipeline HOT 1
- Unable to bundle code with dependencies HOT 5
- inputField Inline support? HOT 1
- Documentation request: cannot chain .inputField
- Unable to add left padding to singleLineMenu? HOT 1
- Is there an example with "more text than fits in a specific rect", to show off scrolling?
- bug: appendLog can not render markup text after Creating TextBox with contentHasMarkup
- doc: some part of documentation is wrong
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terminal-kit.