19
5
In: a string without line breaks*
Allow the user to edit and submit the line
Out: the modified string (optionally with a trailing linebreak)
The line editor must at minimum allow the user to:
move a visible cursor left and right
insert and/or overwrite characters at the cursor position
remove characters at the cursor position
submit the new string, i.e. cease editing cause the modified string to be returned/printed/displayed/saved… (with no other text)
Appreciated, but not required:
explanation of your code.
link to an online testing site that can demonstrate your program/function
an animated image demonstrating usage (TIO, for instance, does not allow interactivity)
Note:
key-bindings are suggestions only
GUI or visual styling is not required
Examples
In the following, the cursor is illustrated with _
.
In: Just some text
Allow the user to edit:
Just some text_
User presses ← (left arrow key) nine times
Just ̲some text
User presses Del four times
Just ̲ text
User presses any
Just any_text
User presses Enter
Out: Just any text
In: Remove me
Allow the user to edit:
Remove me_
User presses Backspace nine times
_
User presses Enter
Out: (empty string)
* To prevent trivial editor solutions, this must either be supplied via a different input method than the editing commands, or must be separated from them by a newline or similar.
Do we have to use those exact keypresses for i/o? Also, can we create a file to save the text to? – Rɪᴋᴇʀ – 2017-04-24T13:11:09.363
1
@Riker key-bindings are suggestions only. Input and output methods follow PPCG defaults.
– Adám – 2017-04-24T13:14:01.147Can the string contain newlines? And can a newline be used to "submit"? – Conor O'Brien – 2017-04-24T14:23:14.010
@ConorO'Brien No; *Simple line editor*. Yes; The editor must at minimum allow the user to: (...) 4. submit the new string – Adám – 2017-04-24T14:24:51.673
1It would be nice if you specified line in the actual body of the question, as titles on this site are not exactly specifications... – Conor O'Brien – 2017-04-24T14:26:49.140
@ConorO'Brien OK? – Adám – 2017-04-24T14:27:25.507
Is it needed to respond to the
Enter
key? Or can I bind my edit control directly to a variable? – sergiol – 2017-04-24T19:58:08.673@sergiol The line editor must at minimum allow the user to (...) submit the new string. key-bindings are suggestions only. As long as there is a possibility for the user to signal that editing is done, it is fine. – Adám – 2017-04-24T20:18:29.437
So, Is my answer valid or not? – sergiol – 2017-04-24T20:19:02.677
@sergiol Can the user click the
╳
button to stop editing and let surrounding code continue? – Adám – 2017-04-24T20:21:23.770Clicking the X button will exit from application. – sergiol – 2017-04-24T20:29:06.480
Let us continue this discussion in chat.
– Adám – 2017-04-24T20:29:38.603A nice challenge but too vulnerable to abuse – Beta Decay – 2017-04-25T18:09:54.373
@BetaDecay I think I've managed to patch up the worst holes. Do you see any more? – Adám – 2017-04-25T18:10:35.587
I don't think so – Beta Decay – 2017-04-25T18:18:14.517
Bash, 2 bytes:
vi
(jk) – programmer5000 – 2017-07-24T17:43:19.943@programmer5000 How do you submit? – Adám – 2017-07-24T17:45:21.280
@programmer5000 APL, 1 byte:
∇
– Adám – 2017-07-24T17:46:35.517I think this is one case where banning builtins would've been a good idea. – 12Me21 – 2018-03-26T19:57:37.017
@12Me21 But which build-ins? Those that do the entire job? Half of it? Rather than hard-to-define bans, we need a better voting culture that promotes ingenuity – Adám – 2018-03-26T21:15:52.923