goblinfactory / konsole

Home of the simple console library consisting of ProgressBar, Window, Form, Draw & MockConsole (C# console progress bar with support for single or multithreaded progress updates) Window is a 100%-ish console compatible window, supporting all normal console writing to a windowed section of the screen, supporting scrolling and clipping of console output.
719 stars 62 forks source link

Input done right! :D #53

Open goblinfactory opened 4 years ago

goblinfactory commented 4 years ago

I want to be able to capture input safely at a region on the screen or at the current cursor position, and be able to specify the data type to limit to, and for the input to be constrained by the containing window.

For example

var window = Window.OpenBox("name", 40,3);
window.Write("Name:   ");
var name = window.ReadText(60, { Scroll = true }); // limits entry to 60 characters, allow scrolling
window.Write("Age:      ");
var age = window.ReadNumber(0, 120); 
window.Write("Discount: ");
var discount = window.ReadDecimal(0, 100, 2); // min, max, decimals 

Because the inputs are being entered inside a window, all text must be clipped by the containing window.

Scrolling content

If the text area left for the input is less than the available characters, then when the user reaches the end of the line, the textbox must scroll the contents.

for example in the code above the window is only 40 characters wide,and the caption takes up space, so the name which can be up to 60 characters, will cause the text to scroll when.

Support keystrokes

Input at X,Y

var name = window.ReadAt(10,10, Input.Number, width:30);

Move between inputs using tab and arrow keys

The arrow keys will move you to the next active input based on the inputs location on the screen. Pressing up will move you to the nearest input above you, etc.

// pseudo code
var person = Window.Read<Person>(CaptionWidth:14, 
  p => 
  new Input(p.Name, 10,10, Text, width:30, caption:"Name"),
   new Input(p.Surname, 0,11, Text, width:30, caption:"Surname"), 
   new Input(p.X, 0, 1, Integer(0,50), width:4, caption:"X:"), 
   new Input(p.Y, 6,1, Integer(0,50), width:4, caption:"Y:"), 
);

Pressing tab moves you between inputs, inputs are highlighted with a default theme, typically black on white for active input, and white and black for inactive.

Themeable inputs

be able to set the foreground and background color of active, current, inactive items.

cascading theme to reduce code required to render

Inputs to read their theme from a window. if a parent window has no theme, then the check for theme bubbles up to the parents parent, so that themes cascade. Windows to come with decent default themes.