Emulating a mainframe

General FreeBASIC programming questions.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Emulating a mainframe

Post by jj2007 »

grindstone wrote:Eagerly. Start the snippet, modify the preset sentence like in a textbox, then press return.

Code: Select all

#Include "stringmod.bi"
Congrats, it works just fine! I have my own Input$() here, but so far I had not seen an implementation in another language that worked. And yet, it is such a common task. My compliments.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Emulating a mainframe

Post by Gablea »

If I have multiply input locations on a text interface I understand I could use locate to fill in the background of the area how would I do the actual input? Would I declare day TextInput(6) as string

And the use a case select to direct the keyboard input to the required field?
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Emulating a mainframe

Post by grindstone »

jj2007 wrote:My compliments.
Thank you, but it's not so amazing, I wrote the first version in the 90es for the QBasic interpreter, so it had more than 2 decades to grow. <smile> Its real strength is the capability of running a plugin. So you can get a string e.g. from a database that is treated the same way as if you typed it in.

EDIT:
@Gablea: I don't know if I understood you right, but if you don't have mouse support for your interface, the common way is to choose the text field with the function keys (F1...F12). And of course SELECT CASE is a good way to handle it.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Emulating a mainframe

Post by Gablea »

Sorry maybe I did not explain myself enough


|---------------------------------------------------------------------------------------|
| Product Edit |
|---------------------------------------------------------------------------------------|
| Barcode Number : ############# |
| Description : ############################ |
| |
|Sale Location : #### Sup Cat #### |
| Age Resctricted # Age limit ## |
|---------------------------------------------------------------------------------------|

in the above example the feilds are repesented by the # (the # would be solid green). so when I type how would i display what is being typed in say the Barcode number Box and then when the user press enter or tab it would then move down to the Description (etc etc) (example the text would be black and the # would stay solid green)

If some one could help me with this part the rest I have planed would be a lot easier as I want to do this with 3-4 other applications but this part has always been the bit I can not work out
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Emulating a mainframe

Post by BasicCoder2 »

Code: Select all

+---------------------------------------------------------------------------------------+
| Product Edit                                                                          |
|---------------------------------------------------------------------------------------|
| Barcode Number : #############                                                        |
| Description : ############################                                            |
|                                                                                       |
| Sale Location : #### Sup Cat ####                                                     |
| Age Resctricted # Age limit ##                                                        |
+---------------------------------------------------------------------------------------+
I am not sure what exactly the problem is. I am assuming it is about having one main computer that does all the processing but which can monitor any number of connected "dumb" computers being used simply as i/o devices?

I assume here the main computer has to monitor the input from the dumb computers and then in turn send data to be displayed back to those dumb computers?

So if someone sits down at a dumb computer they can treat it as if typing into the actual main computer?
I don't know how all that is managed. Do you "log in". What if two people are using their own dumb computer to communicate at the same time?

It is the paucity of explanation in terms of your hardware setup that is an issue for me.

In the modern restaurants I see the little touch pads that waiters carry around as perhaps a modern day version of a dumb terminal. They use them to enter the order and it is sent to the kitchen display and point of sale.

You talk about the color scheme but that is really a minor issue dependent on the hardware being used as a dumb terminal.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Emulating a mainframe

Post by Gablea »

Sorry I mean how would the program acually handle that as the way i have seen it is the dumb terminal would connect to a linux server using on the TTY terminal and can run a program as normal (so it would handle input like it was running on a local machine)

I have done a few tests on my freinds Linux server setup and we can connect upto 5 dumb terminals via the Comport and we can run tui applications with no problem on each machine (as each screen run independent to the other)

So for example I have this screen

Image

a user would start to type a barcode and press enter and then they would start typing the description (example below)

Image

How would the program handle the input fields? I can do the background with no problem i would just like advice on how to handle the multiple input fields I ask as I am only use to doing programs that have one field at a time
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Emulating a mainframe

Post by badidea »

A very simplistic way (probably lacking all requirements):

Code: Select all

dim as string text

do
	color 7, 0: cls
	locate 10, 10
	color 2,0 : print "Input1: ";
	color 0,2 : input "", text
	locate 11, 10
	color 2,0 : print "Input2: ";
	color 0,2 : input "", text
	locate 12, 10
	color 2,0 : print "Input3: ";
	color 0,2 : input "", text
loop
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Emulating a mainframe

Post by Gablea »

that has given me a few ideas

I could use that as a basis and use things like len() to work out the length on the input etc

would ucase work on the input or can that only be used after the enter key has been pressed?
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Emulating a mainframe

Post by badidea »

The default input function is a bit limited. Conversion to ucase only afterwards.

ASCII window demo:

Code: Select all

type tuiRect_type
	dim as integer x, y 'Lets waste a few bytes. Don't tell MrSwiss :-P
	dim as integer w, h 'dimensions
	dim as integer fgc, bgc 'colors
end type

const as integer NUM_TUI_INFO = 3

type tuiText_type
	dim as string title
	dim as string info(NUM_TUI_INFO-1)
	dim as integer infoSelection
end type

sub xycPrint(x as integer, y as integer, text as string, fgColor as integer, bgColor as integer)
	locate y, x
	color fgColor, bgColor
	print text;	
end sub

function textFixedLen(text as string, length as integer) as string
	dim as string temp = text
	if len(text) > length then
		temp = left(text, length - 2) & ".."
	else
		temp = text & string(length - len(text), " ")
	end if
	return temp
end function

function tuiWindow(rect as tuiRect_type, text as tuiText_type) as integer
	dim as string s, l
	dim as integer y, i
	y = rect.y
	s = "o" & string(rect.w - 2, "-") & "o" 
	xycPrint(rect.x, y, s, rect.fgc, rect.bgc)
	y += 1
	s = "| " & textFixedLen(text.title, rect.w - 4) & " |" 
	xycPrint(rect.x, y, s, rect.fgc, rect.bgc)
	y += 1
	s = "o" & string(rect.w - 2, "-") & "o" 
	xycPrint(rect.x, y, s, rect.fgc, rect.bgc)
	y += 1
	for i = 0 to NUM_TUI_INFO-1
		if i = text.infoSelection then
			xycPrint(rect.x, y, "| ", rect.fgc, rect.bgc)
			s = textFixedLen(text.info(i), rect.w - 4)
			xycPrint(rect.x + 2, y, s, rect.bgc, rect.fgc)
			xycPrint(rect.x + rect.w - 2, y, " |", rect.fgc, rect.bgc)
		else
			s = "| " & textFixedLen(text.info(i), rect.w - 4) & " |"
			xycPrint(rect.x, y, s, rect.fgc, rect.bgc)
		end if
		y += 1
	next
	s = "o" & string(rect.w - 2, "-") & "o" 
	xycPrint(rect.x, y, s, rect.fgc, rect.bgc)
	return 0
end function

function tuiClear(rectNow as tuiRect_type, rectPrev as tuiRect_type) as integer
	dim as integer y
	dim as string s
	'check top (window moved down)
	if rectNow.y > rectPrev.y then
		for y = rectPrev.y to rectNow.y - 1
			s = string(rectPrev.w, " ")
			xycPrint(rectPrev.x, y, s, 7, 0)
		next
	end if
	'check bottom (window moved up or size decreased)
	if (rectNow.y + rectNow.h) < (rectPrev.y + rectPrev.h) then
		for y = (rectNow.y + rectNow.h) to (rectPrev.y + rectPrev.h) - 1
			s = string(rectPrev.w, " ")
			xycPrint(rectPrev.x, y, s, 7, 0)
		next
	end if
	'check left (window moved right)
	if rectNow.x > rectPrev.x then
		for y = rectPrev.y to (rectPrev.y + rectPrev.h) - 1
			s = string(rectNow.x - rectPrev.x, " ")
			xycPrint(rectPrev.x, y, s, 7, 0)
		next
	end if
	'check right (window moved left or size decreased)
	if (rectNow.x + rectNow.w) < (rectPrev.x + rectPrev.w) then
		for y = rectPrev.y to (rectPrev.y + rectPrev.h) - 1
			s = string((rectPrev.x + rectPrev.w) - (rectNow.x + rectNow.w), " ")
			xycPrint(rectPrev.x + rectPrev.w - 1, y, s, 7, 0)
		next
	end if
	return 0
end function

dim as tuiText_type tuiText

tuiText.title = "TUI is awesome!"
tuiText.info(0) = "<badidea> made this just for fun :-)"
tuiText.info(1) = date() & " / " & time()
tuiText.info(2) = "Look mama, oldschool ascii based windows in FreeBASIC"
tuiText.infoSelection = 1

dim as tuiRect_type tuiRect = type(20, 5, 40, NUM_TUI_INFO + 4, 14, 1)
dim as tuiRect_type tuiRectPrev = tuiRect
dim as double t1 = timer, t2 = timer
dim as integer xDir = +1, yDir = +1

while inkey <> chr(27) '<escape> to exit
	locate 1,1,0
	tuiText.info(1) = date() & " / " & time()
	tuiWindow(tuiRect, tuiText)
	tuiClear(tuiRect, tuiRectPrev)
	if timer > t1 + 0.5 then
		t1 = timer
		tuiText.infoSelection = (tuiText.infoSelection + 1) mod 3
	end if
	if timer > t2 + 0.25 then
		t2 = timer
		tuiRectPrev = tuiRect 'save prevoius location
		if xDir > 0 then
			if tuiRect.x + tuiRect.w >= 79 then xDir = -1
		else
			if tuiRect.x <= 1 then xDir = +1
		end if
		tuiRect.x += xDir
		if yDir > 0 then
			if tuiRect.y + tuiRect.h >= 24 then yDir = -1
		else
			if tuiRect.y <= 1 then yDir = +1
		end if
		tuiRect.y += yDir
	end if
	sleep 1,1
wend
locate ,,1
Still need to implement the clear function. A simple CLS gives horrible flickering. Added, code updated.
Last edited by badidea on Aug 15, 2018 21:16, edited 1 time in total.
Post Reply