Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Repository: https://github.com/cancerberoSgx/termgui
See TODO
gem install termgui
require 'termgui'
screen = Screen.new
left = screen.append_child Col.new(width: 0.4, height: 0.99, style: { bg: 'red' })
(0..8).map { |i| left.append_child Label.new(text: "Label_#{i}") }
right = screen.append_child Col.new(width: 0.6, height: 0.99, x: 0.4, style: {bg: 'blue'))
(0..4).map do |i|
right.append_child Button.new(
text: "Button_#{i}", x: 0.5,
style: {focus: {fg: '#ed5525'}},
action: proc { open_modal(screen: screen, title: "Button_#{i}") }
)
end
screen.start
Result:
cd termui
bundler install
sh bin/test
sh bin/doc
sh bin/dev # rails server
sh bin/watch # tests in watch mode
TODO
### low level (working) examples
TODO
TODO
TODO
TODO
Some high level element attributes implemented:
By default, children inherit parent style. If element.get_attribute('style-cascade') == 'prevent'
it won't happen - this is the children won't be affected by its parent style and only its own is rendered.
elements with focusable attribute will be able to be focused when user press focus keys (configurable in screen.focus.keys ). By default screen.focus.keys == { next: ['tab'], prev: ['S-tab'] }.
focusable elements will emit "focus" and "blur" events
When focused, the attribute focused will be true and the element is able to receive "action" event (see actionable, action-keys below)
this is useful to implement actionable widgets like buttons that, when focused, can emit "action" events when certain keys are pressed (by default ENTER)
focused elements with attribute "actionable" will emit "action" events if user press action-keys (enter by default) when they are focused. Action keys can be configured globally using screen.action.keys or by element with attribute action-keys. Both could be a string or array.
automatically trigger an action event wneh an element is focused. helpful for selectbox so no enter is needed for working
automatically escapes an entered element on blur. helpful for selectbox so no escape is needed for switching focus - so it behaves like buttons
This is useful to implement textarea / textinput widgets for which we don't want to trigger focus or action events when user is writing text. When an enterable element (that also should be focusable) receives "action" it is set to "entered" mode. (whey you are writing text, you want TAB S-tab, enter, etc to actually insert characters and don't emit "focus" "action", etc events...)
When an element is on this mode (only one at a time) the rest of the elements will stop receiving common events like focus or action until it leaves the entered mode. . This could happen programmatically or by receiving "escape" event, by default pressing ESC will provoke "escape" event which will set entered = false and enable normal events again (like focus, action, etc). When entered==true, the entered element will listen for input independently and emit "input" events.
the enter event by default is provoked by "action" (enter) so it can be configured individually using action-keys.
the escape event by default pressing "escape" can be configurable per element using attribute escape-keys (just like action-keys)
TODO: configure to better play with focus: enter-on-focus to automatically "entered" without "action" and automatically "escape" on "blur" (focus will keep working on this case). Also is not clear how escape plays with change
screen.renderer.no_buffer = true
. Genereally don't needed in production.** initial design stories**
TODO / proposal
require 'termgui'
class AppExplorer < Column
def initialize(model)
super
@model=model
@text = append_child(text: Textarea.new model.text, onChange: {|e| print e.key})
@text.onChange {|e| print e.key}
end
end
screen = Screen.new
main = Row.new
left = main.append_child(Column.new 0.3)
right = main.append_child(Column.new 0.7)
explorer = left.append_child(AppExplorer.new model)
editor = right.append_child(AppEditor.new model)
screen start
TODO / proposal
class MyWidget < Column
def initialize
super 0.5
append_children [
{type: Row, height: 0.6, children: [
{type: Input, value: 'edit me', width: 0.5, onChange: {|e|print e} },
{type: Label, text: 'edit me'},
]}
{type: Button, text: 'click me', onClick: {|e|print e}},
]
end
end
{type: Button, text: 'click me', onclick: {|e|print e}},
vs
Button.new text: 'click me', onclick: {|e|print e}},
{type: Row, height: 0.6, children: [
{type: Input, value: 'edit me', width: 0.5, onChange: {|e|print e} },
{type: Label, text: 'hello'},
]}
vs
Row.new height: 0.6, children: [
Input.new value: 'edit me', width: 0.5, onChange: {|e|print e},
Label new: label: 'hello'
]
style = { '.primary': { bg: 'red', fg: 'black' bold: true } } screen.append_child(Column.new children: [ Label.new text: 'are you sure?', Button.new ])
TODO / proposal
s=Screen.new
b=Button.new(parent: s.document, width: 0.3, height: 0.3, left: 0, top: 0, label: 'click me', onClick: { |e| alert "#{e.target.label} clicked!" })
s.start
(no HTML DOM at all, just drawing)
screen = Screen.new
screen.renderer.rect(2,3,9,3,'-', {fg: 'yellow', bg: 'gray'})
screen.renderer.text(x: 3, y: 4,text; 'click me', style: Style.new(fg: '#ffee11', bg: 'black', bold: true))
screen=Screen.new
screen.event.add_listener('key', {|e| exit 0 if e.key=='q'})
renderer.text(text: 'press q to exit')
Screen: contains document, renderer, buffer, Input
Renderer: responsible of drawing given pixels to the terminal
Buffer: maintains screen as bitmap structure (so users can read the current screen contents like a bitmap)
Document: Node subclass analog to html's (access to parent screen)
Node: DOM like representation analog to html's (children, attributes)
Element: Node subclass analog to html's (border, margin, padding)
Input: responsible of user input - notifies screen - emitter
I'm author of npm.org/flor that although has superior terminal support (tput) I would like to re implement a similar library for ruby, writing it from scratch (currently learning ruby).
{bg: 'red', s: 'hello'}
into a string with ansi codesadd features from npm.org/flor:
TODO
Screen, renderer, input are responsible of basic terminal styles like bg, fg, bold, etc.
On top of the screen, renderer and input a document object model like HTML DOM is supported. See Node, Element, Style, etc. Some features based on HTML supported are:
Some high level utilities, like the focus/action management, work on top of this DOM so probably 99% of users will want to go that way for building their GUIs.
FAQs
Unknown package
We found that termgui demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.