Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #59288 > unrolled thread
| Started by | Andreas Klimas <klimas@w3group.de> |
|---|---|
| First post | 2017-05-15 12:48 +0200 |
| Last post | 2017-05-27 22:19 -0700 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.forth
more sophisticated accept ? Andreas Klimas <klimas@w3group.de> - 2017-05-15 12:48 +0200
Re: more sophisticated accept ? Ron Aaron <rambamist@gmail.com> - 2017-05-15 14:01 +0300
Re: more sophisticated accept ? hughaguilar96@gmail.com - 2017-05-22 11:10 -0700
Re: more sophisticated accept ? hughaguilar96@gmail.com - 2017-05-27 05:28 -0700
Re: more sophisticated accept ? hughaguilar96@gmail.com - 2017-05-27 22:19 -0700
| From | Andreas Klimas <klimas@w3group.de> |
|---|---|
| Date | 2017-05-15 12:48 +0200 |
| Subject | more sophisticated accept ? |
| Message-ID | <ofc0s8$ks9$1@dont-email.me> |
I want to present the user a value which he could edit. like accept but with a predefined value. May be with left and right scrolling. is there such a support in the standard ? Or any tiny 'curses' like library for ANSI-forth ? If not, no problem, I will do it myself. thank you
[toc] | [next] | [standalone]
| From | Ron Aaron <rambamist@gmail.com> |
|---|---|
| Date | 2017-05-15 14:01 +0300 |
| Message-ID | <ofc1jn$mo5$1@dont-email.me> |
| In reply to | #59288 |
On 05/15/17 13:48, Andreas Klimas wrote: > I want to present the user a value which he could edit. > like accept but with a predefined value. May be with > left and right scrolling. > > is there such a support in the standard ? > Or any tiny 'curses' like library for ANSI-forth ? > > If not, no problem, I will do it myself. I don't know about in ANS, but 8th's 'accept' does do that as well as handle history. It doesn't use 'readline', and it's utf8-aware, so it was a bit of fun to implement...
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2017-05-22 11:10 -0700 |
| Message-ID | <92d1d763-26a2-4a2a-9920-924c261ab7c3@googlegroups.com> |
| In reply to | #59288 |
On Monday, May 15, 2017 at 3:48:50 AM UTC-7, Andreas Klimas wrote:
> I want to present the user a value which he could edit.
> like accept but with a predefined value. May be with
> left and right scrolling.
>
> is there such a support in the standard ?
> Or any tiny 'curses' like library for ANSI-forth ?
>
> If not, no problem, I will do it myself.
>
> thank you
I have GET-STR in the novice package that is similar to ACCEPT (I actually forgot that ACCEPT was available when I wrote GET-STR). This doesn't present the user with a string to edit --- that is a good idea though --- I can upgrade GET-STR to do that.
In the meantime, this is GET-STR that I have currently:
8 constant <backspace>
9 constant <tab>
13 constant <cr>
27 constant <esc>
: get-str ( -- str ) \ used for user-interface input
<cstr
begin key dup <cr> <> while
dup case
<backspace> of dup emit space emit 1 -cstr endof
<tab> of drop endof
<esc> of drop endof
dup emit char+cstr
endcase
repeat drop
cstr> ;
\ I wasn't aware of ACCEPT when I wrote GET-STR --- I will leave GET-STR in though, because it offers some flexibility in handling editing chars.
: get-float ( -- ) \ float: -- n
begin get-str count >float not while
cr ." You did not enter a valid number. Try again: " repeat ;
: y/n? ( adr cnt -- y/n? true | false ) \ top flag indicates if string is a valid Yea or Nay
-leading \ -- adr cnt
0= if drop false exit then \ -- adr
c@ \ -- char
dup [char] Y = if drop true true exit then
dup [char] y = if drop true true exit then
dup [char] N = if drop false true exit then
dup [char] n = if drop false true exit then
drop false ;
: <get-y/n> ( -- y/n? true | false ) \ valid?
get-str count y/n? ;
: get-y/n ( -- flag )
begin <get-y/n> not while
cr ." You did not enter a valid Yea or Nay. Try again: " repeat ;
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2017-05-27 05:28 -0700 |
| Message-ID | <12602023-5942-4fd8-8399-3a5094b20b8f@googlegroups.com> |
| In reply to | #59732 |
On Monday, May 22, 2017 at 11:10:31 AM UTC-7, hughag...@gmail.com wrote:
> On Monday, May 15, 2017 at 3:48:50 AM UTC-7, Andreas Klimas wrote:
> > I want to present the user a value which he could edit.
> > like accept but with a predefined value. May be with
> > left and right scrolling.
> >
> > is there such a support in the standard ?
> > Or any tiny 'curses' like library for ANSI-forth ?
> >
> > If not, no problem, I will do it myself.
> >
> > thank you
>
> I have GET-STR in the novice package that is similar to ACCEPT (I actually forgot that ACCEPT was available when I wrote GET-STR). This doesn't present the user with a string to edit --- that is a good idea though --- I can upgrade GET-STR to do that.
>
> In the meantime, this is GET-STR that I have currently:
>
> 8 constant <backspace>
> 9 constant <tab>
> 13 constant <cr>
> 27 constant <esc>
>
> : get-str ( -- str ) \ used for user-interface input
> <cstr
> begin key dup <cr> <> while
> dup case
> <backspace> of dup emit space emit 1 -cstr endof
> <tab> of drop endof
> <esc> of drop endof
> dup emit char+cstr
> endcase
> repeat drop
> cstr> ;
>
> \ I wasn't aware of ACCEPT when I wrote GET-STR --- I will leave GET-STR in though, because it offers some flexibility in handling editing chars.
>
> : get-float ( -- ) \ float: -- n
> begin get-str count >float not while
> cr ." You did not enter a valid number. Try again: " repeat ;
>
> : y/n? ( adr cnt -- y/n? true | false ) \ top flag indicates if string is a valid Yea or Nay
> -leading \ -- adr cnt
> 0= if drop false exit then \ -- adr
> c@ \ -- char
> dup [char] Y = if drop true true exit then
> dup [char] y = if drop true true exit then
> dup [char] N = if drop false true exit then
> dup [char] n = if drop false true exit then
> drop false ;
>
> : <get-y/n> ( -- y/n? true | false ) \ valid?
> get-str count y/n? ;
>
> : get-y/n ( -- flag )
> begin <get-y/n> not while
> cr ." You did not enter a valid Yea or Nay. Try again: " repeat ;
Well, I upgraded GET-STR to take an init-str --- this was trivial:
8 constant <backspace>
9 constant <tab>
13 constant <cr>
27 constant <esc>
: get-str ( init-str -- str ) \ used for user-interface input
<cstr
dup count type +cstr
begin key dup <cr> <> while
dup case
<backspace> of dup emit space emit 1 -cstr endof
<tab> of drop endof
<esc> of drop endof
dup emit char+cstr
endcase
repeat drop
cstr> ;
\ GET-STR is a slight upgrade on ACCEPT because it takes an init-str that is used as a default.
\ This GET-STR is not compatible with the GET-STR in previous NOVICE.4TH releases that didn't have an init-str.
: get-float ( -- ) \ float: -- n
begin c" 0." get-str count >float not while
cr ." You did not enter a valid number. Try again: " repeat ;
: y/n? ( adr cnt -- y/n? true | false ) \ top flag indicates if string is a valid Yea or Nay
-leading \ -- adr cnt
0= if drop false exit then \ -- adr
c@ \ -- char
dup [char] Y = if drop true true exit then
dup [char] y = if drop true true exit then
dup [char] N = if drop false true exit then
dup [char] n = if drop false true exit then
drop false ;
: <get-y/n> ( -- y/n? true | false ) \ valid?
c" Y" get-str count y/n? ;
: get-y/n ( -- flag )
begin <get-y/n> not while
cr ." You did not enter a valid Yea or Nay. Try again: " repeat ;
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2017-05-27 22:19 -0700 |
| Message-ID | <6001bd0b-653e-437b-84b2-1afe636e8fef@googlegroups.com> |
| In reply to | #59288 |
On Monday, May 15, 2017 at 3:48:50 AM UTC-7, Andreas Klimas wrote: > I want to present the user a value which he could edit. > like accept but with a predefined value. May be with > left and right scrolling. > > is there such a support in the standard ? > Or any tiny 'curses' like library for ANSI-forth ? > > If not, no problem, I will do it myself. > > thank you Be aware that AT-XY doesn't work in VFX (Windows version), and Stephen Pelc isn't going to fix the problem. I found this out when I wrote my ARENA.4TH game: https://groups.google.com/forum/#!topic/comp.lang.forth/N5B1AbXqPfQ%5B76-100%5D If you are planning on writing a program to do data-entry, such as CURSES was often used for, this isn't going to work.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web