Wie handhabe ich wchar/wint mit PureBasic richtig?
Weitere allgemeine Tipps sind gern gesehen.
Beispiel: (update: 20.02.2022)
Code: Alles auswählen
;whiptail
; Box options:
; --msgbox <text> <height> <width>
; --yesno <text> <height> <width>
; --infobox <text> <height> <width>
; --inputbox <text> <height> <width> [init]
; --passwordbox <text> <height> <width> [init]
; --textbox <file> <height> <width>
; --menu <text> <height> <width> <listheight> [tag item] ...
; --checklist <text> <height> <width> <listheight> [tag item status]...
; --radiolist <text> <height> <width> <listheight> [tag item status]...
; --gauge <text> <height> <width> <percent>
; Options: (depend on box-option)
; --clear clear screen on exit
; --defaultno Default no button
; --Default-item <string> set Default string
; --fb, --fullbuttons use full buttons
; --nocancel no cancel button
; --yes-button <text> set text of yes button
; --no-button <text> set text of no button
; --ok-button <text> set text of ok button
; --cancel-button <text> set text of cancel button
; --noitem don't display items
; --notags don't display tags
; --separate-output output one line at a time
; --output-fd <fd> output To fd, Not stdout
; --title <title> display title
; --backtitle <backtitle> display backtitle
; --scrolltext force vertical scrollbars
; --topleft put window in top-left corner
; -h, --help print this message
; -v, --version print version information
;-color_test
; export NEWT_COLORS='
; window=,red
; border=white,red
; textbox=white,red
; button=black,white
; '
; ## Set newt color palette For dialogs
; NEWT_COLORS_0='
; root=,blue
; '
; NEWT_COLORS_1='
; root=,blue
; checkbox=,blue
; entry=,blue
; label=blue,
; actlistbox=,blue
; helpline=,blue
; roottext=,blue
; emptyscale=blue
; disabledentry=blue,
; '
; NEWT_COLORS_2='
; root=green,black
; border=green,black
; title=green,black
; roottext=white,black
; window=green,black
; textbox=white,black
; button=black,green
; compactbutton=white,black
; listbox=white,black
; actlistbox=black,white
; actsellistbox=black,green
; checkbox=green,black
; actcheckbox=black,green
; '
; NEWT_COLORS_3='
; root=white,black
; border=black,lightgray
; window=lightgray,lightgray
; shadow=black,gray
; title=black,lightgray
; button=black,cyan
; actbutton=white,cyan
; compactbutton=black,lightgray
; checkbox=black,lightgray
; actcheckbox=lightgray,cyan
; entry=black,lightgray
; disentry=gray,lightgray
; label=black,lightgray
; listbox=black,lightgray
; actlistbox=black,cyan
; sellistbox=lightgray,black
; actsellistbox=lightgray,black
; textbox=black,lightgray
; acttextbox=black,cyan
; emptyscale=,gray
; fullscale=,cyan
; helpline=white,black
; roottext=lightgrey,black
; '
; export NEWT_COLORS=$NEWT_COLORS_0
;Dies ist eine nicht definierte Programm-Version:
;-> mit noch vielen Fehlern und sehr vielen Erweiterungsmöglichkeiten.
;Die Kommentare sind in "Denglisch" (Deutsch/Englisch).
EnableExplicit
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
DeclareModule Termi
#LC_ALL = 0
Enumeration Colors
#COLOR_BLACK = 0
#COLOR_RED
#COLOR_GREEN
#COLOR_YELLOW
#COLOR_BLUE
#COLOR_MAGENTA
#COLOR_CYAN
#COLOR_WHITE
EndEnumeration
;line graphics
#ACS_ULCORNER = 'l' ;'┌'
#ACS_LLCORNER = 'm' ;'└'
#ACS_URCORNER = 'k' ;'┐'
#ACS_LRCORNER = 'j' ;'┘'
#ACS_LTEE = 't' ;'├'
#ACS_RTEE = 'u' ;'┤'
#ACS_BTEE = 'v' ;'┴'
#ACS_TTEE = 'w' ;'┬'
#ACS_HLINE = 'q' ;'─'
#ACS_VLINE = 'x' ;'│'
#ACS_PLUS = 'n' ;'┼'
#ACS_S1 = 'o'
#ACS_S9 = 's'
#ACS_DIAMOND = '`'
#ACS_CKBOARD = 'a'
#ACS_DEGREE = 'f'
#ACS_PLMINUS = 'g'
#ACS_BULLET = '~'
#ACS_LARROW = ','
#ACS_RARROW = '+'
#ACS_DARROW = '.'
#ACS_UARROW = '-'
#ACS_BOARD = 'h'
#ACS_LANTERN = 'i'
#ACS_BLOCK = '0'
;/* double lines */
#WACS_BDDB = 'C'
#WACS_DDBB = 'D'
#WACS_BBDD = 'B'
#WACS_DBBD = 'A'
#WACS_DBDD = 'G'
#WACS_DDDB = 'F'
#WACS_DDBD = 'H'
#WACS_BDDD = 'I'
#WACS_BDBD = 'R'
#WACS_DBDB = 'Y'
#WACS_DDDD = 'E'
;/* thick lines */
#WACS_BTTB = 'L'
#WACS_TTBB = 'M'
#WACS_BBTT = 'K'
#WACS_TBBT = 'J'
#WACS_TBTT = 'U'
#WACS_TTTB = 'T'
#WACS_TTBT = 'V'
#WACS_BTTT = 'W'
#WACS_BTBT = 'Q'
#WACS_TBTB = 'X'
#WACS_TTTT = 'N'
;keys
#KEY_CODE_YES = $40 ;/* A wchar_t contains a key code */
#KEY_MIN = $41 ;/* Minimum curses key */
#KEY_BREAK = $41 ;/* Break key (unreliable) */
#KEY_SRESET = $158 ;/* Soft (partial) reset (unreliable) */
#KEY_RESET = $159 ;/* Reset Or hard reset (unreliable) */
#KEY_DOWN = $102 ;/* down-arrow key */
#KEY_UP = $103 ;/* up-arrow key */
#KEY_LEFT = $104 ;/* left-arrow key */
#KEY_RIGHT = $105;/* right-arrow key */
#KEY_HOME = $106 ;/* home key */
#KEY_BACKSPACE = $107 ;/* backspace key */
#KEY_F0 = $108 ;/* Function keys. Space For 64 */
Macro KEY_F(n) ;/* Value of function key n */
(#KEY_F0+(n))
EndMacro
#KEY_DL = $148 ;/* delete-line key */
#KEY_IL = $149 ;/* insert-line key */
#KEY_DC = $14a ;/* delete-character key */
#KEY_IC = $14b ;/* insert-character key */
#KEY_EIC = $14c;/* sent by rmir Or smir in insert mode */
#KEY_CLEAR = $14d ;/* clear-screen Or erase key */
#KEY_EOS = $14e ;/* clear-To-End-of-screen key */
#KEY_EOL = $14f ;/* clear-To-End-of-line key */
#KEY_SF = $150 ;/* scroll-forward key */
#KEY_SR = $151 ;/* scroll-backward key */
#KEY_NPAGE = $152 ;/* Next-page key */
#KEY_PPAGE = $153 ;/* previous-page key */
#KEY_STAB = $154 ;/* set-tab key */
#KEY_CTAB = $155 ;/* clear-tab key */
#KEY_CATAB = $156 ;/* clear-all-tabs key */
#KEY_ENTER = $157 ;/* enter/send key */
#KEY_PRINT = $15a ;/* print key */
#KEY_LL = $15b ;/* lower-left key (home down) */
#KEY_A1 = $15c ;/* upper left of keypad */
#KEY_A3 = $15d ;/* upper right of keypad */
#KEY_B2 = $15e ;/* center of keypad */
#KEY_C1 = $15f ;/* lower left of keypad */
#KEY_C3 = $160 ;/* lower right of keypad */
#KEY_BTAB = $161 ;/* back-tab key */
#KEY_BEG = $162 ;/* begin key */
#KEY_CANCEL = $163;/* cancel key */
#KEY_CLOSE = $164 ;/* close key */
#KEY_COMMAND = $165 ;/* command key */
#KEY_COPY = $166 ;/* copy key */
#KEY_CREATE = $167 ;/* create key */
#KEY_END = $168 ;/* End key */
#KEY_EXIT = $169 ;/* exit key */
#KEY_FIND = $16a ;/* find key */
#KEY_HELP = $16b ;/* help key */
#KEY_MARK = $16c ;/* mark key */
#KEY_MESSAGE = $16d ;/* message key */
#KEY_MOVE = $16e ;/* move key */
#KEY_NEXT = $16f ;/* Next key */
#KEY_OPEN = $170 ;/* open key */
#KEY_OPTIONS = $171 ;/* options key */
#KEY_PREVIOUS = $172;/* previous key */
#KEY_REDO = $173 ;/* redo key */
#KEY_REFERENCE = $174 ;/* reference key */
#KEY_REFRESH = $175 ;/* refresh key */
#KEY_REPLACE = $176 ;/* replace key */
#KEY_RESTART = $177 ;/* restart key */
#KEY_RESUME = $178 ;/* resume key */
#KEY_SAVE = $179 ;/* save key */
#KEY_SBEG = $17a ;/* shifted begin key */
#KEY_SCANCEL = $17b ;/* shifted cancel key */
#KEY_SCOMMAND = $17c ;/* shifted command key */
#KEY_SCOPY = $17d ;/* shifted copy key */
#KEY_SCREATE = $17e ;/* shifted create key */
#KEY_SDC = $17f ;/* shifted delete-character key */
#KEY_SDL = $180 ;/* shifted delete-line key */
#KEY_SELECT = $181 ;/* Select key */
#KEY_SEND = $182 ;/* shifted End key */
#KEY_SEOL = $183 ;/* shifted clear-To-End-of-line key */
#KEY_SEXIT = $184 ;/* shifted exit key */
#KEY_SFIND = $185 ;/* shifted find key */
#KEY_SHELP = $186 ;/* shifted help key */
#KEY_SHOME = $187 ;/* shifted home key */
#KEY_SIC = $188 ;/* shifted insert-character key */
#KEY_SLEFT = $189 ;/* shifted left-arrow key */
#KEY_SMESSAGE = $18a ;/* shifted message key */
#KEY_SMOVE = $18b ;/* shifted move key */
#KEY_SNEXT = $18c ;/* shifted Next key */
#KEY_SOPTIONS = $18d ;/* shifted options key */
#KEY_SPREVIOUS = $18e ;/* shifted previous key */
#KEY_SPRINT = $18f ;/* shifted print key */
#KEY_SREDO = $190 ;/* shifted redo key */
#KEY_SREPLACE = $191 ;/* shifted replace key */
#KEY_SRIGHT = $192 ;/* shifted right-arrow key */
#KEY_SRSUME = $193 ;/* shifted resume key */
#KEY_SSAVE = $194 ;/* shifted save key */
#KEY_SSUSPEND = $195 ;/* shifted suspend key */
#KEY_SUNDO = $196 ;/* shifted undo key */
#KEY_SUSPEND = $197 ;/* suspend key */
#KEY_UNDO = $198 ;/* undo key */
#KEY_MOUSE = $199 ;/* Mouse event has occurred */
#KEY_RESIZE = $19a ;/* Terminal resize event */
#KEY_EVENT = $19b ;/* We were interrupted by an event */
#KEY_MAX = $1ff ;/* Maximum key value is 0633 */
;attributes
#NCURSES_ATTR_SHIFT = 8
Macro NCURSES_BITS(mask,shift)
((mask) << ((shift) + #NCURSES_ATTR_SHIFT))
EndMacro
#A_NORMAL = 0
#A_ATTRIBUTES = NCURSES_BITS(~(1 - 1), 0)
#A_CHARTEXT = (NCURSES_BITS(1, 0) - 1)
#A_COLOR = NCURSES_BITS(((1) << 8) - 1, 0)
#A_STANDOUT = NCURSES_BITS(1, 8)
#A_UNDERLINE = NCURSES_BITS(1, 9)
#A_REVERSE = NCURSES_BITS(1, 10)
#A_BLINK = NCURSES_BITS(1, 11)
#A_DIM = NCURSES_BITS(1, 12)
#A_BOLD = NCURSES_BITS(1, 13)
#A_ALTCHARSET = NCURSES_BITS(1, 14)
#A_INVIS = NCURSES_BITS(1, 15)
#A_PROTECT = NCURSES_BITS(1, 16)
#A_HORIZONTAL = NCURSES_BITS(1, 17)
#A_LEFT = NCURSES_BITS(1, 18)
#A_LOW = NCURSES_BITS(1, 19)
#A_RIGHT = NCURSES_BITS(1, 20)
#A_TOP = NCURSES_BITS(1, 21)
#A_VERTICAL = NCURSES_BITS(1, 22)
;options (Constructor - new)
#TERMI_DEFAULT = 0
#TERMI_SPECIALKEYS = 1
#TERMI_SCROLLMODE = 2
;options (delete)
#TERMI_DEL_CHAR = 0
#TERMI_DEL_LINE = 1
;options (clear)
#TERMI_CLEAR_NORMAL = 0
#TERMI_CLEAR_COLOR = 1
#TERMI_CLEAR_LINE = 2
#TERMI_CLEAR_NEXT = 3
;options (createLine)
#TERMI_HLINE = 0
#TERMI_VLINE = 1
;options (insertLine)
#TERMI_LINE_INSERT = 0
#TERMI_LINE_REMOVE = 1
;options (waitKey)
#TERMI_WAIT_NONL = 0
#TERMI_WAIT_NL = 1
;Mouse_Support
Macro NCURSES_MOUSE_MASK(b, m)
((m) << (((b) - 1) * 5))
EndMacro
#NCURSES_BUTTON_RELEASED = $1
#NCURSES_BUTTON_PRESSED = $2
#NCURSES_BUTTON_CLICKED = $4
#NCURSES_DOUBLE_CLICKED = $8
#NCURSES_TRIPLE_CLICKED = $10
#NCURSES_RESERVED_EVENT = $20
;/* event masks */
#BUTTON1_RELEASED = NCURSES_MOUSE_MASK(1, #NCURSES_BUTTON_RELEASED)
#BUTTON1_PRESSED = NCURSES_MOUSE_MASK(1, #NCURSES_BUTTON_PRESSED)
#BUTTON1_CLICKED = NCURSES_MOUSE_MASK(1, #NCURSES_BUTTON_CLICKED)
#BUTTON1_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(1, #NCURSES_DOUBLE_CLICKED)
#BUTTON1_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(1, #NCURSES_TRIPLE_CLICKED)
#BUTTON2_RELEASED = NCURSES_MOUSE_MASK(2, #NCURSES_BUTTON_RELEASED)
#BUTTON2_PRESSED = NCURSES_MOUSE_MASK(2, #NCURSES_BUTTON_PRESSED)
#BUTTON2_CLICKED = NCURSES_MOUSE_MASK(2, #NCURSES_BUTTON_CLICKED)
#BUTTON2_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(2, #NCURSES_DOUBLE_CLICKED)
#BUTTON2_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(2, #NCURSES_TRIPLE_CLICKED)
#BUTTON3_RELEASED = NCURSES_MOUSE_MASK(3, #NCURSES_BUTTON_RELEASED)
#BUTTON3_PRESSED = NCURSES_MOUSE_MASK(3, #NCURSES_BUTTON_PRESSED)
#BUTTON3_CLICKED = NCURSES_MOUSE_MASK(3, #NCURSES_BUTTON_CLICKED)
#BUTTON3_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(3, #NCURSES_DOUBLE_CLICKED)
#BUTTON3_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(3, #NCURSES_TRIPLE_CLICKED)
#BUTTON4_RELEASED = NCURSES_MOUSE_MASK(4, #NCURSES_BUTTON_RELEASED)
#BUTTON4_PRESSED = NCURSES_MOUSE_MASK(4, #NCURSES_BUTTON_PRESSED)
#BUTTON4_CLICKED = NCURSES_MOUSE_MASK(4, #NCURSES_BUTTON_CLICKED)
#BUTTON4_DOUBLE_CLICKED = NCURSES_MOUSE_MASK(4, #NCURSES_DOUBLE_CLICKED)
#BUTTON4_TRIPLE_CLICKED = NCURSES_MOUSE_MASK(4, #NCURSES_TRIPLE_CLICKED)
#ALL_MOUSE_EVENTS = (NCURSES_MOUSE_MASK(5, $8)-1)
Macro c_int:l:EndMacro
Macro c_bool:i:EndMacro
Structure MEVENT Align #PB_Structure_AlignC
id.c_int ;/* ID To distinguish multiple devices */
x.c_int
y.c_int
z.c_int ;/* event coordinates (character-cell) */
bstate.c_int ;/* button state bits */
EndStructure
ImportC "-lncursesw"
baudrate()
beep()
attroff(attr.i)
attron(attr.i)
attrset(attr.i)
clear()
wclear(win.i)
COLOR_PAIR(n.i)
color_set(cp.i, opts.i)
bkgd(chtype.i)
wbkgd(win.i, chtype.i)
delwin(win.i)
endwin()
has_colors.c_bool()
can_change_color.c_bool()
init_pair(pair.i, fg.i, bg.i)
init_color.i(color.w, r.w, g.w, b.w)
initscr()
mvaddstr(y.i, x.i, str.p-utf8)
mvaddwstr(y.i, x.i, *str.long)
refresh()
start_color()
getmaxx(win.i)
getmaxy(win.i)
mvgetstr(y.i, x.i, *str.p-utf8)
mvget_wstr(y.i, x.i, *str.long)
mvgetn_wstr(y.i, x.i, *str.long, n.i)
move(y.i, x.i)
nocbreak()
noecho()
cbreak()
echo()
raw()
noraw()
curs_set(cur.i)
keypad(win.i, key.c_bool)
getch.c_int()
scrl(n.i)
scroll(win.i)
scrollok.i(win.i, ok.c_bool)
is_scrollok.b(win.i)
getcurx.i(win.i)
getcury.i(win.i)
isendwin.c_bool()
addnwstr(*str.long, n.i)
ins_nwstr(*str.long, n.i)
mvaddnwstr(y.i, x.i, *str.long, n.i)
mvins_nwstr(y.i, x.i, *str.long, n.i)
clrtobot()
clrtoeol()
deleteln()
delch()
mvdelch(y.i, x.i)
insdelln(n.i)
insertln()
has_ic.c_bool()
has_il.c_bool()
hline(c.i, n.i)
hline_set(*chr.long, n.i)
mvhline(y.i, x.i, chtype.c_int, n.i)
mvhline_set(y.i, x.i, *chr.long, n.i)
mvvline(y.i, x.i, chtype.c_int, n.i)
mvvline_set(y.i, x.i, *chr.long, n.i)
vline(c.i, n.i)
vline_set(*chr.long, n.i)
nl()
nonl()
qiflush()
noqiflush()
printw(str.p-utf8)
mvprintw(y.i, x.i, str.p-utf8)
innwstr(*chr.long, n.i)
mvinnwstr(y.i, x.i, *chr.long, n.i)
timeout(time.i)
;Mouse
has_mouse.c_bool()
getmouse(*mouse.MEVENT)
ungetmouse(*mouse.MEVENT)
mousemask(m1.i, *m2.long)
wenclose.c_bool(win.i, x.i, y.i)
mouseinterval(delay.i)
wmouse_trafo.c_bool(win.i, *a.long, *b.long, c.c_bool)
mouse_trafo.c_bool(*a.long, *b.long, c.c_bool)
;screen
scr_dump(str.p-utf8)
scr_init(str.p-utf8)
scr_restore(str.p-utf8)
scr_set(str.p-utf8)
EndImport
Structure item_t
tag.s
itemtext.s
status.s
EndStructure
Interface iTermi
ScreenToFile.i(file.s)
FileToScreen.i(file.s)
setAutoRefresh.i(flip.c_bool)
readOutput.s(max_char.i = 1, x.i = -1, y.i = -1)
setMouseInterval.i(delay.i)
setMouseEvent.i(new_mask.i, *old_mask.integer = 0)
getMouseEvent.i(*mouse_event.MEVENT, button.i = 0, x.i = -1, y.i = -1)
insertLine.i(modus.i = 0, n.i = 1)
createLine.i(alignment.i, chr.i, n.i, x = -1, y = -1)
delete.i(modus.i = 0, x.i = -1, y.i = -1)
write.i(stdout.s, n.i = 1, insert.c_bool = #False, x.i = -1, y.i = -1)
hideInput.i(echo.c_bool)
changeColor.i(pair.i, r.i, g.i, b.i)
setKeymode.i(state.c_bool)
setScrollmode.i(state.c_bool)
scrollLine.i(lines.i)
setPos.i(x.i, y.i)
getPosX.i()
getPosY.i()
setTermBackground.i(bgcolor.i, fgcolor.i = 7)
setTermAttribute.i(attr.i, state.c_bool = #True)
setTermCursor.i(cur.c_bool)
setTermColors.i(pair.i, fgcolor.i, bgcolor.i)
getMaxX.i()
getMaxY.i()
out.i(x.i, y.i, stdout.s)
in.s(x.i, y.i, max_char=100)
waitKey.c_int(modus.i = 0)
setDialogColors(color_str.s)
msgbox.i(title.s, text.s, height.i, width.i, options.s = "")
yesno.i(title.s, text.s, height.i, width.i, options.s = "")
inputbox.s(title.s, text.s, height.i, width.i, init.s = "", options.s = "")
passwordbox.s(title.s, text.s, height.i, width.i, init.s = "", options.s = "")
textbox.i(title.s, file.s, height.i, width.i, options.s = "")
menu.s(title.s, text.s, height.i, width.i, listheight.i, List item.item_t(), options.s = "")
checklist.s(title.s, text.s, height.i, width.i, listheight.i, List item.item_t(), options.s = "")
radiolist.s(title.s, text.s, height.i, width.i, listheight.i, List item.item_t(), options.s = "")
gauge.i(title.s, text.s, height.i, width.i, percent.i, end_count.i, sleep.i, options.s = "")
setItems.i(List item.item_t(), tag.s, itemtext.s, status.c_bool=#False)
clear.i(modus.i = 0, fgcolor.i = 7, bgcolor.i = 0)
free.i()
EndInterface
Declare.i new(fgcolor.i = 7, bgcolor.i = 0, options.i = 0)
EndDeclareModule
Module Termi
#DIALOG = "whiptail"
#UTF8_MEMORY = 8
Global Auto_Refresh = #True
Structure termi_t
vTable.i
run.i
EndStructure
ImportC ""
mbstowcs(*dest,*src,n)
wcstombs(*dest,*src,n)
EndImport
Procedure.i new(fgcolor.i = 7, bgcolor.i = 0, options.i = 0)
Protected *this.termi_t
If GetEnvironmentVariable("LANG") = "de_DE.UTF-8"
setlocale_(#LC_ALL, "de_DE.UTF-8")
Else
setlocale_(#LC_ALL, "en_GB.UTF8")
EndIf
*this = AllocateStructure(termi_t)
If Not *this : ProcedureReturn #False : EndIf
*this\vTable = ?vTable_Termi
*this\run = initscr()
If *this\run
start_color()
If has_colors()
init_pair(1, fgcolor, bgcolor)
color_set(1, #Null)
EndIf
;options
Select options
Case #TERMI_SPECIALKEYS
keypad(*this\run, #True)
Case #TERMI_SCROLLMODE
scrollok(*this\run, #True)
Case #TERMI_SPECIALKEYS + #TERMI_SCROLLMODE
keypad(*this\run, #True)
scrollok(*this\run, #True)
EndSelect
EndIf
ProcedureReturn *this
EndProcedure
Procedure.i Termi_ScreenToFile(*this.termi_t, file.s)
If *this\run
ProcedureReturn scr_dump(file)
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_FileToScreen(*this.termi_t, file.s)
If *this\run
ProcedureReturn scr_restore(file)
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setAutoRefresh(*this.termi_t, flip.b)
If *this\run
If flip = #True
Auto_Refresh = #True
ProcedureReturn 1
Else
Auto_Refresh = #False
ProcedureReturn 0
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.s Termi_readOutput(*this.termi_t, max_char.i = 1, x.i = -1, y.i = -1)
Protected *p_in = AllocateMemory(max_char*#UTF8_MEMORY)
Protected *p_ret = AllocateMemory(MemorySize(*p_in))
Protected ret.s
If *this\run
If x <= -1 Or y <= -1
innwstr(*p_in, max_char)
Else
mvinnwstr(y, x, *p_in, max_char)
EndIf
wcstombs(*p_ret, *p_in, MemorySize(*p_ret))
ret = PeekS(*p_ret, -1, #PB_UTF8)
EndIf
FreeMemory(*p_in):FreeMemory(*p_ret)
If Len(ret) > 0
ProcedureReturn ret
Else
ProcedureReturn "-1"
EndIf
EndProcedure
;Mouse_Support
Procedure.i Termi_setMouseInterval(*this.termi_t, delay.i)
If *this\run
mouseinterval(delay.i)
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setMouseEvent(*this.termi_t, new_mask.i, *old_mask.integer = 0)
If *this\run
mousemask(new_mask, *old_mask)
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_getMouseEvent(*this.termi_t, *mouse_event.MEVENT, button.i = 0, x.i = -1, y.i = -1)
If *this\run
If has_mouse()
If x <= -1 Or y <= -1
ungetmouse(*mouse_event)
If getmouse(*mouse_event) = 0
If button <> 0
If *mouse_event\bstate = button
ProcedureReturn #True
EndIf
Else
ProcedureReturn #True
EndIf
Else
ProcedureReturn #False
EndIf
Else
ungetmouse(*mouse_event)
If getmouse(*mouse_event) = 0 And button <> 0
If *mouse_event\x = x And *mouse_event\y = y
If button <> 0
If *mouse_event\bstate = button
ProcedureReturn #True
EndIf
Else
ProcedureReturn #True
EndIf
EndIf
Else
ProcedureReturn #False
EndIf
EndIf
Else
ProcedureReturn -2
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_insertLine(*this.termi_t, modus.i = 0, n.i = 1)
If *this\run
If modus = #TERMI_LINE_INSERT
insertln()
ElseIf modus = #TERMI_LINE_REMOVE
insdelln(n)
EndIf
If Auto_Refresh = #True
refresh()
EndIf
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_createLine(*this.termi_t, alignment.i, chr.i, n.i, x = -1, y = -1)
If *this\run
If x <= -1 Or y <= -1
If alignment = #TERMI_HLINE
hline(chr, n)
ElseIf alignment = #TERMI_VLINE
vline(chr, n)
EndIf
Else
If alignment = #TERMI_HLINE
mvhline(y, x, chr, n)
ElseIf alignment = #TERMI_VLINE
mvvline(y, x, chr, n)
EndIf
EndIf
If Auto_Refresh = #True
refresh()
EndIf
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_delete(*this.termi_t, modus.i = 0, x.i = -1, y.i = -1)
If *this\run And has_il() = #True
If modus = #TERMI_DEL_CHAR
If x <= -1 Or y <= -1
delch()
Else
mvdelch(y.i, x.i)
EndIf
ElseIf modus = #TERMI_DEL_LINE
deleteln()
EndIf
If Auto_Refresh = #True
refresh()
EndIf
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_write(*this.termi_t, stdout.s, n.i = 1, insert.b = #False, x.i = -1, y.i = -1)
Protected *p_stdout = UTF8(stdout)
Protected *p_out = AllocateMemory(MemorySize(@stdout)*2)
If *this\run And has_il() = #True
If x <= -1 Or y <= -1
If insert = #False
mbstowcs(*p_out, *p_stdout, MemorySize(@stdout)*2)
addnwstr(*p_out, n)
ElseIf insert = #True
mbstowcs(*p_out, *p_stdout, MemorySize(@stdout)*2)
ins_nwstr(*p_out, n)
EndIf
Else
If insert = #False
mbstowcs(*p_out, *p_stdout, MemorySize(@stdout)*2)
mvaddnwstr(y.i, x.i, *p_out, n)
ElseIf insert = #True
mbstowcs(*p_out, *p_stdout, MemorySize(@stdout)*2)
mvins_nwstr(y.i, x.i, *p_out, n)
EndIf
EndIf
If Auto_Refresh = #True
refresh()
EndIf
EndIf
If *pout
FreeMemory(*p_stdout):FreeMemory(*p_out)
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_hideInput(*this.termi_t, echo.b)
If *this\run
If echo = #True
noecho()
ProcedureReturn 1
Else
echo()
ProcedureReturn 0
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_changeColor(*this.termi_t, pair.i, r.i, g.i, b.i)
If *this\run
If can_change_color()
init_color(pair, r, g, b)
start_color()
ProcedureReturn 0
Else
ProcedureReturn -2
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setKeymode(*this.termi_t, state.b)
If *this\run
If state = #True
keypad(*this\run, #True)
ProcedureReturn 1
Else
keypad(*this\run, #False)
ProcedureReturn 0
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setScrollmode(*this.termi_t, state.b)
If *this\run
If state = #True
scrollok(*this\run, #True)
ProcedureReturn 1
Else
scrollok(*this\run, #False)
ProcedureReturn 0
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_scrollLine(*this.termi_t, lines.i)
If *this\run
If is_scrollok(*this\run)
scrl(lines)
If Auto_Refresh = #True
refresh()
EndIf
ProcedureReturn 0
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setPos(*this.termi_t, x.i, y.i)
If *this\run
move(y, x)
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_getPosX(*this.termi_t)
If *this\run
ProcedureReturn getcurx(*this\run)
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_getPosY(*this.termi_t)
If *this\run
ProcedureReturn getcury(*this\run)
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setTermBackground(*this.termi_t, bgcolor.i, fgcolor.i = 7)
If *this\run
If has_colors()
init_pair(1, fgcolor, bgcolor)
color_set(1, #Null)
bkgd(COLOR_PAIR(1))
refresh()
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setTermCursor(*this.termi_t, cur.b)
If *this\run
If cur = #True
curs_set(#True)
ProcedureReturn 1
Else
curs_set(#False)
ProcedureReturn 0
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setTermAttribute(*this.termi_t, attr.i, state.b = #True)
If *this\run
If state = #True
attron(attr)
ProcedureReturn 1
ElseIf state = #False
attroff(attr)
ProcedureReturn 0
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setTermColors(*this.termi_t, pair.i, fgcolor.i, bgcolor.i)
If *this\run
If has_colors()
init_pair(pair, fgcolor, bgcolor)
ProcedureReturn 0
Else
ProcedureReturn -2
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_getMaxX(*this.termi_t)
If *this\run
ProcedureReturn getmaxx(*this\run)
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_getMaxY(*this.termi_t)
If *this\run
ProcedureReturn getmaxy(*this\run)
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_out(*this.termi_t, x.i, y.i, stdout.s)
Protected *p_stdout = UTF8(stdout)
Protected *p_out = AllocateMemory(MemorySize(@stdout)*2)
If *this\run
mbstowcs(*p_out, *p_stdout, MemorySize(@stdout)*2)
mvaddwstr(y, x, *p_out)
If Auto_Refresh = #True
refresh()
EndIf
EndIf
If *pout
FreeMemory(*p_stdout):FreeMemory(*p_out)
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.s Termi_in(*this.termi_t, x.i, y.i, max_char=100)
Protected *p_in = AllocateMemory(max_char*#UTF8_MEMORY)
Protected *p_ret = AllocateMemory(MemorySize(*p_in))
Protected ret.s
If *this\run
mvgetn_wstr(y, x, *p_in, max_char)
wcstombs(*p_ret, *p_in, MemorySize(*p_ret))
ret = PeekS(*p_ret, -1, #PB_UTF8)
If Auto_Refresh = #True
refresh()
EndIf
EndIf
FreeMemory(*p_in):FreeMemory(*p_ret)
If Len(ret) > 0
ProcedureReturn ret
Else
ProcedureReturn "-1"
EndIf
EndProcedure
Procedure.c_int Termi_waitKey(*this.termi_t, modus.i = 0)
If *this\run
If modus = #TERMI_WAIT_NONL
nonl()
ElseIf modus = #TERMI_WAIT_NL
nl()
EndIf
ProcedureReturn getch()
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setDialogColors(*this.termi_t, color_str.s)
If *this\run
SetEnvironmentVariable("NEWT_COLORS", color_str)
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_msgbox(*this.termi_t, title.s, text.s, height.i, width.i, options.s="")
If *this\run
RunProgram(#DIALOG, UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --msgbox \"" + text + ~"\" " + Str(height) + " " + Str(width), "", #PB_Program_Wait)
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_yesno(*this.termi_t, title.s, text.s, height.i, width.i, options.s="")
Protected exit.i, prog.i
If *this\run
prog = RunProgram(#DIALOG, UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --yesno \"" + text + ~"\" " + Str(height) + " " + Str(width), "", #PB_Program_Open | #PB_Program_Wait)
If IsProgram(prog)
While ProgramRunning(prog)
;...
Wend
exit = ProgramExitCode(prog)
CloseProgram(prog)
ProcedureReturn exit
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.s Termi_inputbox(*this.termi_t, title.s, text.s, height.i, width.i, init.s="", options.s="")
Protected exit.s, prog.i
Protected *pstr, *modus
Protected *pout.character, plen.i
*pstr = UTF8(#DIALOG + " " + UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --inputbox \"" + text + ~"\" " + Str(height) + " " + Str(width) + " " + UnescapeString(init) + " 3>&1 1>&2 2>&3")
*modus = UTF8("r")
If *this\run
prog = popen_(*pstr, *modus)
If( prog <> #Null )
getline_(@*pout, @plen, prog)
EndIf
pclose_(prog)
exit = PeekS(*pout, #PB_Any, #PB_UTF8)
FreeMemory(*pstr):FreeMemory(*modus)
ProcedureReturn exit
Else
ProcedureReturn "-1"
EndIf
EndProcedure
Procedure.s Termi_passwordbox(*this.termi_t, title.s, text.s, height.i, width.i, init.s="", options.s="")
Protected exit.s, prog.i
Protected *pstr, *modus
Protected *pout.character, plen.i
*pstr = UTF8(#DIALOG + " " + UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --passwordbox \"" + text + ~"\" " + Str(height) + " " + Str(width) + " " + UnescapeString(init) + " 3>&1 1>&2 2>&3")
*modus = UTF8("r")
If *this\run
prog = popen_(*pstr, *modus)
If( prog <> #Null )
getline_(@*pout, @plen, prog)
EndIf
pclose_(prog)
exit = PeekS(*pout, #PB_Any, #PB_UTF8)
FreeMemory(*pstr):FreeMemory(*modus)
ProcedureReturn exit
Else
ProcedureReturn "-1"
EndIf
EndProcedure
Procedure.i Termi_textbox(*this.termi_t, title.s, file.s, height.i, width.i, options.s="")
Protected exit.i, prog.i
If *this\run
prog = RunProgram(#DIALOG, UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --textbox \"" + file + ~"\" " + Str(height) + " " + Str(width), "", #PB_Program_Open | #PB_Program_Wait)
If IsProgram(prog)
While ProgramRunning(prog)
;...
Wend
exit = ProgramExitCode(prog)
CloseProgram(prog)
ProcedureReturn exit
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.s Termi_menu(*this.termi_t, title.s, text.s, height.i, width.i, listheight.i, List item.item_t(), options.s="")
Protected exit.s, prog.i, prog_str.s
Protected *pstr, *modus
Protected *pout.character, plen.i
prog_str = #DIALOG + " " + UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --menu \"" + text + ~"\" " + Str(height) + " " + Str(width) + " " + Str(listheight) + " "
ForEach item()
prog_str + ~"\"" + item()\tag + ~"\" \"" + item()\itemtext + ~"\" "
Next
prog_str + " 3>&1 1>&2 2>&3"
*pstr = UTF8(prog_str)
*modus = UTF8("r")
If *this\run
prog = popen_(*pstr, *modus)
If( prog <> #Null )
getline_(@*pout, @plen, prog)
EndIf
pclose_(prog)
exit = PeekS(*pout, #PB_Any, #PB_UTF8)
FreeMemory(*pstr):FreeMemory(*modus)
ProcedureReturn exit
Else
ProcedureReturn "-1"
EndIf
EndProcedure
Procedure.s Termi_checklist(*this.termi_t, title.s, text.s, height.i, width.i, listheight.i, List item.item_t(), options.s="")
Protected exit.s, prog.i, prog_str.s
Protected *pstr, *modus
Protected *pout.character, plen.i
prog_str = #DIALOG + " " + UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --checklist \"" + text + ~"\" " + Str(height) + " " + Str(width) + " " + Str(listheight) + " "
ForEach item()
prog_str + ~"\"" + item()\tag + ~"\" \"" + item()\itemtext + ~"\" \"" + item()\status + ~"\" "
Next
prog_str + " 3>&1 1>&2 2>&3"
*pstr = UTF8(prog_str)
*modus = UTF8("r")
If *this\run
prog = popen_(*pstr, *modus)
If( prog <> #Null )
getline_(@*pout, @plen, prog)
EndIf
pclose_(prog)
exit = PeekS(*pout, #PB_Any, #PB_UTF8)
FreeMemory(*pstr):FreeMemory(*modus)
ProcedureReturn exit
Else
ProcedureReturn "-1"
EndIf
EndProcedure
Procedure.s Termi_radiolist(*this.termi_t, title.s, text.s, height.i, width.i, listheight.i, List item.item_t(), options.s="")
Protected exit.s, prog.i, prog_str.s
Protected *pstr, *modus
Protected *pout.character, plen.i
prog_str = #DIALOG + " " + UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --radiolist \"" + text + ~"\" " + Str(height) + " " + Str(width) + " " + Str(listheight) + " "
ForEach item()
prog_str + ~"\"" + item()\tag + ~"\" \"" + item()\itemtext + ~"\" \"" + item()\status + ~"\" "
Next
prog_str + " 3>&1 1>&2 2>&3"
*pstr = UTF8(prog_str)
*modus = UTF8("r")
If *this\run
prog = popen_(*pstr, *modus)
If( prog <> #Null )
getline_(@*pout, @plen, prog)
EndIf
pclose_(prog)
exit = PeekS(*pout, #PB_Any, #PB_UTF8)
FreeMemory(*pstr):FreeMemory(*modus)
ProcedureReturn exit
Else
ProcedureReturn "-1"
EndIf
EndProcedure
Procedure.i Termi_gauge(*this.termi_t, title.s, text.s, height.i, width.i, percent.i, end_count.i, sleep.i, options.s="")
Protected exit.i, prog.i, count.i = percent
If *this\run
If percent < 0 Or percent > 100
percent = 100
EndIf
If end_count < 0 Or end_count < percent Or end_count > 100
end_count = 100
EndIf
prog = RunProgram(#DIALOG, UnescapeString(options) + ~" --clear --title \"" + title + ~"\" --gauge \"" + text + ~"\" " + Str(height) + " " + Str(width) + " " + Str(percent), "", #PB_Program_Open|#PB_Program_Write|#PB_Program_UTF8)
If IsProgram(prog)
While ProgramRunning(prog) And (count <= end_count)
;...
Repeat
WriteProgramStringN(prog, Str(count), #PB_UTF8)
Delay(sleep)
count + 1
Until count >= end_count
Wend
CloseProgram(prog)
exit = end_count
ProcedureReturn exit
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_setItems(*this.termi_t, List item.item_t(), tag.s, itemtext.s, status.b=#False)
If *this\run
AddElement(item())
item()\tag = tag
item()\itemtext = itemtext
If status = #True
item()\status = "ON"
ElseIf status = #False
item()\status = "OFF"
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_clear(*this.termi_t, modus.i = 0, fgcolor.i = 7, bgcolor.i = 0)
If *this\run
If modus = #TERMI_CLEAR_COLOR
If has_colors()
init_pair(1, fgcolor, bgcolor)
color_set(1, #Null)
EndIf
bkgd(COLOR_PAIR(1))
clear()
refresh()
ElseIf modus = #TERMI_CLEAR_LINE
clrtoeol()
refresh()
ElseIf modus = #TERMI_CLEAR_NEXT
clrtobot()
refresh()
ElseIf modus = #TERMI_CLEAR_NORMAL
clear()
refresh()
EndIf
ProcedureReturn 0
Else
ProcedureReturn -1
EndIf
EndProcedure
Procedure.i Termi_free(*this.termi_t)
If *this\run
clear()
delwin(*this\run)
endwin()
refresh()
FreeStructure(*this)
If isendwin()
ProcedureReturn 0
Else
ProcedureReturn -2
EndIf
Else
ProcedureReturn -1
EndIf
EndProcedure
DataSection
vTable_Termi:
Data.i @Termi_ScreenToFile(), @Termi_FileToScreen()
Data.i @Termi_setAutoRefresh(), @Termi_readOutput()
Data.i @Termi_setMouseInterval(), @Termi_setMouseEvent(), @Termi_getMouseEvent(), @Termi_insertLine()
Data.i @Termi_createLine(), @Termi_delete(), @Termi_write(), @Termi_hideInput()
Data.i @Termi_changeColor(), @Termi_setKeymode(), @Termi_setScrollmode(), @Termi_scrollLine()
Data.i @Termi_setPos(), @Termi_getPosX(), @Termi_getPosY(), @Termi_setTermBackground()
Data.i @Termi_setTermAttribute(), @Termi_setTermCursor(), @Termi_setTermColors(), @Termi_getMaxX()
Data.i @Termi_getMaxY(), @Termi_out(), @Termi_in(), @Termi_waitKey(), @Termi_setDialogColors()
Data.i @Termi_msgbox(), @Termi_yesno(), @Termi_inputbox(), @Termi_passwordbox()
Data.i @Termi_textbox(), @Termi_menu(), @Termi_checklist(), @Termi_radiolist()
Data.i @Termi_gauge(), @Termi_setItems(), @Termi_clear(), @Termi_free()
EndDataSection
EndModule
CompilerElse
Debug "Ein Fehler ist aufgetreten."
End -1
CompilerEndIf
;-Main
CompilerIf #PB_Compiler_IsMainFile = #True And #PB_Compiler_OS = #PB_OS_Linux
UseModule Termi
Global.i th, tw
Global.i quit = 0
Global.i k = 0
Global.s k_str, g_str
Global.i akt_x, akt_y
Global sys.iTermi = new(7, 0, #TERMI_SPECIALKEYS|#TERMI_SCROLLMODE)
sys\setDialogColors("root=,green window=,red border=white,red textbox=green,black button=black,green")
sys\setTermColors(1, #COLOR_GREEN, #COLOR_BLACK)
sys\setTermColors(2, #COLOR_RED, #COLOR_BLACK)
th = sys\getMaxY()
tw = sys\getMaxX()
;sys\setKeymode(#True)
Procedure HSyntax(txt.s, px.i, py.i)
Protected read_all.s, count.i, j.i = 0
Protected Dim ipos.i(sys\getMaxX())
Protected c.s = "+"
count = CountString(txt, "+")
;Debug count
If count > 0
For j = 0 To count-1
If j > 0
ipos(j) = FindString(txt, c, ipos(j-1) + Len(c))
Else
ipos(j) = FindString(txt, c)
EndIf
sys\setTermAttribute(COLOR_PAIR(2), #True)
sys\write(c, Len(c), #False, ipos(j)-1, py)
sys\setTermAttribute(COLOR_PAIR(2), #False)
Next
EndIf
EndProcedure
sys\setAutoRefresh(#False)
sys\clear(#TERMI_CLEAR_COLOR, #COLOR_GREEN, #COLOR_BLACK)
;Key-Event-Loop
Repeat
While quit <> 1
k = sys\waitKey()
If k = #PB_Key_Escape
quit = 1
ElseIf k = KEY_F(1) ;Help
sys\ScreenToFile("screen_output.txt")
sys\msgbox("Hilfe", "Es ist keine weitere Hilfe implementiert", 20, 50)
clear()
sys\waitKey()
sys\FileToScreen("screen_output.txt")
ElseIf k = KEY_F(2) ;Save
If sys\ScreenToFile("screen_output.txt") = 0
sys\out(tw/2 - 13, th-1, "Der Text wurde gespeichert")
EndIf
ElseIf k = KEY_F(3) ;Open
sys\FileToScreen("screen_output.txt")
Break 1
ElseIf k = #KEY_DOWN Or k = #PB_Key_Return
sys\setPos(sys\getPosX(), sys\getPosY() + 1)
ElseIf k = #KEY_UP
sys\setPos(sys\getPosX(), sys\getPosY() - 1)
ElseIf k = #KEY_LEFT
sys\setPos(sys\getPosX() - 1, sys\getPosY())
ElseIf k = #KEY_RIGHT
sys\setPos(sys\getPosX() + 1, sys\getPosY())
ElseIf k = #KEY_BACKSPACE
sys\delete()
If sys\getPosX() = 0 And sys\getPosY() > 0
sys\setPos(sys\getMaxX()-1, sys\getPosY()-1)
EndIf
ElseIf k = #KEY_DC
sys\setPos(sys\getPosX()-1, sys\getPosY())
sys\delete(#TERMI_DEL_CHAR, sys\getPosX()+1, sys\getPosY())
ElseIf k = KEY_F(5)
Debug g_str
EndIf
akt_x = sys\getPosX()
akt_y = sys\getPosY()
k_str + Chr(k)
g_str = sys\readOutput(tw, 0, akt_y) ;Eine Zeile einlesen.
HSyntax(g_str, akt_x, akt_y) ;Zeichen einfärben (+)
sys\setPos(akt_x, akt_y)
refresh()
Wend
Until quit = 1
sys\free()
UnuseModule Termi
CompilerEndIf