• fried brain

    From X V Lxxix to All on Friday, May 09, 2008 10:54:00
    Can anyone take a look at this and tell me why, when given a string and a specified width for word wrapping, it sometimes trims the string way too short, or 3 or 4 characters too long? I've been frying my brain with this and I just can't get it straightened out:

    this.FitMsg=function(text)
    {
    var msg=text;
    if(console.strlen(msg)>=this.width) {
    while(console.strlen(msg)>=this.width) {
    var test_index=this.width;
    while(console.strlen(text.substring(0,test_index)) <this.width)
    {
    if(msg.charAt(test_index)==" " ||
    msg.charAt(test_index+1)==" ") break;
    else if(msg.charAt(test_index)=="\1") {
    test_index++;
    }
    test_index++;
    }
    var push=this.RemoveSpaces(msg.substring (0,test_index));
    if(push.lastIndexOf(" ")>(this.width/2)) {
    test_index=push.lastIndexOf(" ");
    push=this.RemoveSpaces(push.substring (0,test_index));
    }
    this.messages.push(push);
    this.log.Log("adding text to msg buffer: " + push);
    msg=this.RemoveSpaces(msg.slice(test_index));
    }
    this.messages.push(this.RemoveSpaces(msg));
    }
    else this.messages.push(text);
    while(this.messages.length>this.height)
    this.message_history=this.messages.shift();
    this.needs_update=true;
    }
    this.RemoveSpaces=function(text)
    {
    while(text.indexOf(" ")==0) text=text.slice(1);
    return truncsp(text);
    }


    this is an excerpt from a larger piece of code, so some of the variables used in the functions are declared elsewhere.
  • From X V Lxxix to X V Lxxix on Friday, May 09, 2008 11:02:30
    Can anyone take a look at this and tell me why, when given a string and a specified width for word wrapping, it sometimes trims the string way too short, or 3 or 4 characters too long? I've been frying my brain with this and I just can't get it straightened out:

    this.FitMsg=function(text)
    {

    ugh nevermind I figured it out almost immediately after I posted that..
  • From Deuce@SYNCNIX to X V Lxxix on Friday, May 09, 2008 13:40:56
    Re: fried brain
    By: X V Lxxix to All on Fri May 09 2008 10:54 am

    Can anyone take a look at this and tell me why, when given a string and a specified width for word wrapping, it sometimes trims the string way too short, or 3 or 4 characters too long? I've been frying my brain with this and I just can't get it straightened out:

    Have you looked at the word_wrap() global function?

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From MCMLXXIX@MDJ to Deuce on Friday, May 09, 2008 23:20:31
    Re: fried brain
    By: Deuce to X V Lxxix on Fri May 09 2008 13:40:56

    Re: fried brain
    By: X V Lxxix to All on Fri May 09 2008 10:54 am

    Can anyone take a look at this and tell me why, when given a string and a specified width for word wrapping, it sometimes trims the string way too short, or 3 or 4 characters too long? I've been frying my brain with this and I just can't get it straightened out:

    Have you looked at the word_wrap() global function?


    yes.. it wraps to a new line on the left side. I needed to make something that wraps within a specified "window" on the screen. I'm pretty sure it does that anyway. I'm actually checking it right now

    ---
    ■ Synchronet ■ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Deuce@SYNCNIX to MCMLXXIX on Saturday, May 10, 2008 11:07:46
    Re: fried brain
    By: MCMLXXIX to Deuce on Fri May 09 2008 11:20 pm

    Have you looked at the word_wrap() global function?


    yes.. it wraps to a new line on the left side. I needed to make something that wraps within a specified "window" on the screen. I'm pretty sure it does that anyway. I'm actually checking it right now

    You can pass in the width as an argument. :-)

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From MCMLXXIX@MDJ to Deuce on Sunday, May 11, 2008 17:35:22
    Re: fried brain
    By: Deuce to MCMLXXIX on Sat May 10 2008 11:07:46

    Re: fried brain
    By: MCMLXXIX to Deuce on Fri May 09 2008 11:20 pm

    Have you looked at the word_wrap() global function?


    yes.. it wraps to a new line on the left side. I needed to make something that wraps within a specified "window" on the screen. I'm pretty sure it does that anyway. I'm actually checking it right now

    You can pass in the width as an argument. :-)


    Yeah, but it still wraps to the left side of the screen. I need it wrap away from the left side. Unless I'm just not doing it right... that is always a possibility when it comes to me.

    ---
    ■ Synchronet ■ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Deuce@SYNCNIX to MCMLXXIX on Monday, May 12, 2008 12:44:52
    Re: fried brain
    By: MCMLXXIX to Deuce on Sun May 11 2008 05:35 pm

    You can pass in the width as an argument. :-)


    Yeah, but it still wraps to the left side of the screen. I need it wrap
    away from the left side. Unless I'm just not doing it right... that is always a possibility when it comes to me.

    I'm sure I misunderstand the question. The word_wrap() function doesn't do anything with the screen.

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From MCMLXXIX@MDJ to Deuce on Monday, May 12, 2008 16:30:53
    Re: fried brain
    By: Deuce to MCMLXXIX on Mon May 12 2008 12:44:52

    Re: fried brain
    By: MCMLXXIX to Deuce on Sun May 11 2008 05:35 pm

    You can pass in the width as an argument. :-)


    Yeah, but it still wraps to the left side of the screen. I need it wrap away from the left side. Unless I'm just not doing it right... that is always a possibility when it comes to me.

    I'm sure I misunderstand the question. The word_wrap() function doesn't do anything with the screen.


    example:

    string="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdfljkh"; console.gotoxy(10,1); //move to the first row, 10 spaces from the left edge

    console.putmsg(word_wrap(string,10));

    result:

    kljhsadflk
    asfdjkhas
    flhsadlfjh
    etc....

    ----------------------------


    What I needed was for the string to wrap at a distance from the left side,
    but the word_wrap function displays the rest of the wrapped lines at the beginning of the next line.

    desired result:

    kljhsadflk
    asfdjkhas
    flhsadlfjh
    etc..

    you dig? I got it working, at any rate, just wanted to get on the same page with you in case you know of a better/easier way to do it.

    -M

    ---
    ■ Synchronet ■ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Deuce@SYNCNIX to MCMLXXIX on Monday, May 12, 2008 15:01:10
    Re: fried brain
    By: MCMLXXIX to Deuce on Mon May 12 2008 04:30 pm

    string="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdfljkh "; console.gotoxy(10,1); //move to the first row, 10 spaces from the left edge

    console.putmsg(word_wrap(string,10));

    Ah...

    console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From MCMLXXIX@MDJ to Deuce on Monday, May 12, 2008 18:10:51
    Re: fried brain
    By: Deuce to MCMLXXIX on Mon May 12 2008 15:01:10

    Re: fried brain
    By: MCMLXXIX to Deuce on Mon May 12 2008 04:30 pm

    string="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdfl "; console.gotoxy(10,1); //move to the first row, 10 spaces from the left edge

    console.putmsg(word_wrap(string,10));

    Ah...

    console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));


    that would work, sort of... but the idea is to make the text wrap within a window at either a menu, or in the midst of another script, so having preceeding spaces would mess up the surrounding graphics. the distance from the left will also be supplied as a variable and will change depending on what's going on..

    you should make word_wrap take a starting_column argument! .... :)

    ---
    ■ Synchronet ■ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Deuce@SYNCNIX to MCMLXXIX on Monday, May 12, 2008 18:44:37
    Re: fried brain
    By: MCMLXXIX to Deuce on Mon May 12 2008 06:10 pm

    console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));


    that would work, sort of... but the idea is to make the text wrap within a window at either a menu, or in the midst of another script, so having preceeding spaces would mess up the surrounding graphics. the distance from the left will also be supplied as a variable and will change depending on what's going on..

    Ok...
    console.putmsg(word_wrap(string, 10).replace(/\n/,"\n\1"+ascii(127+10)));

    you should make word_wrap take a starting_column argument! .... :)

    The word wrap function is in now way connected to output... so a starting_column argument is pointless.

    Regarding windows, they aren't supported natively. You could do this functionality using the graphic.js library though:

    load("graphic.js");
    var window=new Graphic(10,24);
    window.putmsg(word_wrap(1,1,string, window.width));
    window.draw(1, 10);

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Angus McLeod@ANJO to Deuce on Monday, May 12, 2008 23:16:00
    Re: fried brain
    By: Deuce to MCMLXXIX on Mon May 12 2008 18:44:00

    you should make word_wrap take a starting_column argument! .... :)

    The word wrap function is in now way connected to output... so a starting_column argument is pointless.

    You could split() the word_wrap()ed result on /\n/ and process the
    returned array elements individually, to place them in the "window". Where
    is word_wrap() implemented? Could it be altered to optionally return an
    array type?



    ---
    Playing: "I don't even know myself" by "The Who" from the "Who's next" album.
    ■ Synchronet ■ Making sure Jason works OK at The ANJO BBS
  • From MCMLXXIX@MDJ to Deuce on Monday, May 12, 2008 23:10:51
    Re: fried brain
    By: Deuce to MCMLXXIX on Mon May 12 2008 18:44:37

    Re: fried brain
    By: MCMLXXIX to Deuce on Mon May 12 2008 06:10 pm

    console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));


    that would work, sort of... but the idea is to make the text wrap within window at either a menu, or in the midst of another script, so having preceeding spaces would mess up the surrounding graphics. the distance fr the left will also be supplied as a variable and will change depending on what's going on..

    Ok...
    console.putmsg(word_wrap(string, 10).replace(/\n/,"\n\1"+ascii(127+10)));

    you should make word_wrap take a starting_column argument! .... :)

    The word wrap function is in now way connected to output... so a starting_column argument is pointless.

    Regarding windows, they aren't supported natively. You could do this functionality using the graphic.js library though:

    load("graphic.js");
    var window=new Graphic(10,24);
    window.putmsg(word_wrap(1,1,string, window.width));
    window.draw(1, 10);


    I actually had no idea that could be done with Graphic.js, but it didn't seem to work when I tested it anyway. What does word_wrap do? put an \r\n in the supplied string at the supplied width?

    I have a working function for this, and seems to running just fine now... though that console.putmsg(word_wrap..........); line you wrote up there was a learning experience in itself.

    ---
    ■ Synchronet ■ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Deuce@SYNCNIX to Angus McLeod on Tuesday, May 13, 2008 00:01:42
    Re: fried brain
    By: Angus McLeod to Deuce on Mon May 12 2008 11:16 pm

    You could split() the word_wrap()ed result on /\n/ and process the
    returned array elements individually, to place them in the "window". Where is word_wrap() implemented? Could it be altered to optionally return an array type?

    It's implemented in js_global.c. It could return an array, but if you want an array, just do a .split(/[\r\n]+/) or something. That way you get to use cool string methods and I don't have to do anything. :-)

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Deuce@SYNCNIX to MCMLXXIX on Tuesday, May 13, 2008 00:03:20
    Re: fried brain
    By: MCMLXXIX to Deuce on Mon May 12 2008 11:10 pm

    I actually had no idea that could be done with Graphic.js, but it didn't seem to work when I tested it anyway. What does word_wrap do? put an \r\n
    in the supplied string at the supplied width?

    word_wrap() splits a string of text into multiple lines on word boundaries so that no line is longer than the specified width. It will not place a newline in the middle of a word unless that word is longer than the line width.

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From MCMLXXIX@MDJ to Deuce on Tuesday, May 13, 2008 09:11:15
    Re: fried brain
    By: Deuce to MCMLXXIX on Tue May 13 2008 00:03:20

    Re: fried brain
    By: MCMLXXIX to Deuce on Mon May 12 2008 11:10 pm

    I actually had no idea that could be done with Graphic.js, but it didn't seem to work when I tested it anyway. What does word_wrap do? put an \r\n in the supplied string at the supplied width?

    word_wrap() splits a string of text into multiple lines on word boundaries s that no line is longer than the specified width. It will not place a newlin in the middle of a word unless that word is longer than the line width.


    Ok, I actually wasted a lot of time writing my own similar word wrap function, I guess. I didn't realize that word_wrap actually added newline characters to the string as its return value.. makes sense though. Just never thought about it. Should shorten that portion of my code by about 20 lines (yeah....K.I.S.S.)

    ---
    ■ Synchronet ■ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Angus McLeod@ANJO to Deuce on Tuesday, May 13, 2008 20:05:00
    Re: fried brain
    By: Deuce to Angus McLeod on Tue May 13 2008 00:01:00

    Where is word_wrap() implemented? Could it be altered to optionally return an array type?

    It's implemented in js_global.c. It could return an array, but if you want array, just do a .split(/[\r\n]+/) or something. That way you get to use co string methods and I don't have to do anything. :-)

    Lazy bugger! :-)

    ---
    Playing: "The Magdalene laundries" by "Chieftains"
    from the "Tears Of Stone" album.
    ■ Synchronet ■ Making sure Jason works OK at The ANJO BBS