Jump to content




[LUA] Scrolling a certain amount of text without deleting it?

api help lua

29 replies to this topic

#1 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 08:51 AM

I want to scroll text that uses more space than the terminal height, the problem is: whenever I try to scroll up, and then back down the text is gone and doesn't re-appear
Spoiler


#2 GopherAtl

  • Members
  • 888 posts

Posted 09 January 2013 - 09:00 AM

That's just how the built-in term.scroll works, I'm afraid. You'd have to implement something yourself to save more lines than the screen and allow scrolling them.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 09:03 AM

take a look at one i prepared late last year for someone else http://pastebin.com/mqwMPSbB hopefully it can give you some ideas :)

#4 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 11:15 AM

View PostGopherAtl, on 09 January 2013 - 09:00 AM, said:

That's just how the built-in term.scroll works, I'm afraid. You'd have to implement something yourself to save more lines than the screen and allow scrolling them.

Well, ATM all the lines are stored in a table, but I'm not sure how to scroll those lines. Usually, the table has around 20 - 50 lines of text

View PostTheOriginalBIT, on 09 January 2013 - 09:03 AM, said:

take a look at one i prepared late last year for someone else http://pastebin.com/mqwMPSbB hopefully it can give you some ideas :)/>/>

Thanks, but that doesn't work at all because you're printing every line in the table after x number of seconds, and then starting to print from the first line again when you reach the final line

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 02:25 PM

View PostHeracles421, on 09 January 2013 - 11:15 AM, said:

Thanks, but that doesn't work at all because you're printing every line in the table after x number of seconds, and then starting to print from the first line again when you reach the final line

I'm not printing every line. it prints as many lines as can fit on the screen starting from the given position. the one second means it scrolls every one second. that was their use case.

#6 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 02:41 PM

View PostTheOriginalBIT, on 09 January 2013 - 02:25 PM, said:

View PostHeracles421, on 09 January 2013 - 11:15 AM, said:

Thanks, but that doesn't work at all because you're printing every line in the table after x number of seconds, and then starting to print from the first line again when you reach the final line

I'm not printing every line. it prints as many lines as can fit on the screen starting from the given position. the one second means it scrolls every one second. that was their use case.

I wasn't clear enough with my answer, what I ment is that you print all the lines that can be in the screen, after x number of seconds you print the next line at the bottom, scrolling all the other lines upwards, thus making the top one disappear. Once you finish printing the full table it'll print everything again from the first line.
I cannot use this method because of multiple reasons: 1. The table I am using stores paragraphs, not single lines, therefore I cannot print line by line. 2. I want to scroll once the user hits the up/down arrow keys, not automatically

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 02:46 PM

thats a little bit of a better explanation :) ok so user pressing keys is easy to change. just remove the timer and replace it with the key press for keys.up and keys.down when they are pressed you just appropriately change the scroll start... as for the paragraph thing, using print or write doesn't word wrap the line, could you not just have it store each line into the table on its own instead of by paragraph?

#8 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 02:59 PM

View PostTheOriginalBIT, on 09 January 2013 - 02:46 PM, said:

As for the paragraph thing, using print or write doesn't word wrap the line, could you not just have it store each line into the table on its own instead of by paragraph?

Nope, because I'm requesting some things from an external web page and the answers are sent as paragraphs, not line by line

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 03:03 PM

well your going to have to split the paragraph into lines at some point to print anyway.

#10 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 03:10 PM

View PostTheOriginalBIT, on 09 January 2013 - 03:03 PM, said:

well your going to have to split the paragraph into lines at some point to print anyway.

How could I do that? The problem is that the web page sends multiple answers, which have around 3 to 70 words each, so I store each answer in a table which then is printed.
You can try out the program if you want to, just to see how it works.

pastebin get PRUuJxf6 cciri

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 03:17 PM

does that code actually work for you? It crashes for me, and looking at what line its on I think its because I'm getting events that aren't 'http' events and your code panics when it cant .readAll() on it

#12 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 03:21 PM

View PostTheOriginalBIT, on 09 January 2013 - 03:17 PM, said:

does that code actually work for you? It crashes for me, and looking at what line its on I think its because I'm getting events that aren't 'http' events and your code panics when it cant .readAll() on it
It does indeed, actually it works on a server, it works on the Computercraft University. Maybe it's just your computer derping?

#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 03:26 PM

Interesting... I'm using CC-Emu... Anyways as for the 'content' maybe split it into chunks that are no longer than the width of the screen, then store those individual chunks in the table?

#14 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 03:28 PM

View PostTheOriginalBIT, on 09 January 2013 - 03:26 PM, said:

Interesting... I'm using CC-Emu... Anyways as for the 'content' maybe split it into chunks that are no longer than the width of the screen, then store those individual chunks in the table?

Might work, the only downside is the formatting, because I am splitting one answer from another since usually I get more that 1 answer. Not sure if this will be possible at all if I split the content into individual lines

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 03:30 PM

Is there anything distinctive between the answers?

EDIT: Ok so I just typed in this http://api.wolframal...ormat=plaintext and I see what you mean (never used wolframalpha before)... maybe before looping to get the net answer insert a blank line into the table, that way they are separate.

#16 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 03:32 PM

View PostTheOriginalBIT, on 09 January 2013 - 03:30 PM, said:

Is there anything distinctive between the answers?

Yea, for example, if you search about Steve Jobs, you get his full name, biography (date of birth, death, parents, etc) what things he made, how did things changed with all of that, and things like that

#17 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 03:34 PM

Yeh I noticed that, read the edit :)

#18 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 03:41 PM

View PostTheOriginalBIT, on 09 January 2013 - 03:30 PM, said:

Maybe before looping to get the net answer insert a blank line into the table, that way they are separate.

I was thinking about this: If the line is bigger than the screen width, cut it, and repeat this process again. Once the line is smaller than the screen width (last line) add "\n" at the end of the line

#19 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 03:42 PM

That could work too.

#20 Heracles421

  • Members
  • 258 posts

Posted 09 January 2013 - 03:48 PM

And another problem I've thought of, does lua detect words? Because if it doesn't, the line cut could slice a word in half (Wordmicide!)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users