• console.putmsg alternative that returns a string

    From Nightfox@VERT/DIGDIST to All on Tuesday, September 30, 2014 12:39:49
    Is there an alternative to console.putmsg() that returns a string instead of outputting to the console? What I'd like to do is to have @-codes, etc. interpreted in a string and save that string so I can then pass that string to printf() so I can specify a field length for the text.

    Nightfox

    ---
    Synchronet Digital Distortion BBS - digitaldistortionbbs.com
  • From Psi-Jack@VERT/DECKHVN2 to Nightfox on Wednesday, October 01, 2014 09:32:55
    Re: console.putmsg alternative that returns a string
    By: Nightfox to All on Tue Sep 30 2014 12:39 pm

    Is there an alternative to console.putmsg() that returns a string instead of outputting to the console? What I'd like to do is to have @-codes, etc. interpreted in a string and save that string so I can then pass that string to printf() so I can specify a field length for the text.

    I believe what you're looking for is bbs.atcode():

    text = text.replace(/@([^@]+)@/g, function(m, code) {
    return bbs.atcode(code);
    });

    ---
    [Psi-Jack -//- Decker]
    Synchronet Decker's Heaven -//- bbs.deckersheaven.com
  • From Nightfox@VERT/DIGDIST to Psi-Jack on Wednesday, October 01, 2014 07:44:15
    Re: console.putmsg alternative that returns a string
    By: Psi-Jack to Nightfox on Wed Oct 01 2014 09:32:55

    Is there an alternative to console.putmsg() that returns a string
    instead of outputting to the console? What I'd like to do is to
    have @-codes, etc. interpreted in a string and save that string so I
    can then pass that string to printf() so I can specify a field
    length for the text.

    I believe what you're looking for is bbs.atcode():

    text = text.replace(/@([^@]+)@/g, function(m, code) {
    return bbs.atcode(code);
    });

    I saw bbs.atcode() in the docs.. I was hoping for something that handles a whole string, similar to console.putmsg(). bbs.atcode() only interprets a single @-code, which requires writing some more code, but I suppose that will have to do. Thanks.

    Nightfox

    ---
    Synchronet Digital Distortion BBS - digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Wednesday, October 01, 2014 16:13:25
    Re: console.putmsg alternative that returns a string
    By: Nightfox to All on Tue Sep 30 2014 12:39 pm

    Is there an alternative to console.putmsg() that returns a string instead
    of outputting to the console? What I'd like to do is to have @-codes, etc. interpreted in a string and save that string so I can then pass that string to printf() so I can specify a field length for the text.

    I think you're looking for bbs.atcode().

    That said, Synchronet @-codes already support a method for length field specification as well as left and rigth justification:
    http://wiki.synchro.net/custom:atcodes#formatting

    digital man

    Synchronet "Real Fact" #55:
    Synchronet Terminal Server introduced SecureShell (SSH) support w/v3.14a (2006).
    Norco, CA WX: 83.1F, 45.0% humidity, 3 mph ESE wind, 0.00 inches rain/24hrs

    ---
    Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Wednesday, October 01, 2014 18:06:21
    Re: console.putmsg alternative that returns a string
    By: Digital Man to Nightfox on Wed Oct 01 2014 16:13:25

    I think you're looking for bbs.atcode().

    I was hoping for something similar to console.putmsg which would interpret codes in a whole string and return the new string, but I suppose I could write something to do that with bbs.atcode().

    That said, Synchronet @-codes already support a method for length field specification as well as left and rigth justification: http://wiki.synchro.net/custom:atcodes#formatting

    That's not exactly what I'm looking for - What I will be using this for is reading messages posted on sub-boards, which might include @-codes. Those might not necessarily include length formatting. I'll be taking each line from the message and word-wrapping the line (as the interpreted @-code will likely differ in length from the @-code) and then displaying the message line on the screen with a specific width.

    Nightfox

    ---
    Synchronet Digital Distortion BBS - digitaldistortionbbs.com
  • From Psi-Jack@VERT/DECKHVN2 to Nightfox on Thursday, October 02, 2014 08:23:32
    Re: console.putmsg alternative that returns a string
    By: Nightfox to Psi-Jack on Wed Oct 01 2014 07:44 am

    Re: console.putmsg alternative that returns a string
    By: Psi-Jack to Nightfox on Wed Oct 01 2014 09:32:55

    I believe what you're looking for is bbs.atcode():

    text = text.replace(/@([^@]+)@/g, function(m, code) {
    return bbs.atcode(code);
    });

    I saw bbs.atcode() in the docs.. I was hoping for something that handles a whole string, similar to console.putmsg(). bbs.atcode() only interprets a single @-code, which requires writing some more code, but I suppose that will have to do. Thanks.

    Hmm, yeah. I don't think there's anything else. This text.replace itself goes through each beginning and ending @ code block and translates each one, at least as far as I can tell it does. the variable, text, becomes the full at-code translated result.

    Either way, you're welcome, and hope it helps. :)

    ---
    [Psi-Jack -//- Decker]
    Synchronet Decker's Heaven -//- bbs.deckersheaven.com
  • From Psi-Jack@VERT/DECKHVN2 to Digital Man on Thursday, October 02, 2014 08:27:57
    Re: console.putmsg alternative that returns a string
    By: Digital Man to Nightfox on Wed Oct 01 2014 04:13 pm

    Re: console.putmsg alternative that returns a string
    By: Nightfox to All on Tue Sep 30 2014 12:39 pm

    Is there an alternative to console.putmsg() that returns a string
    instead of outputting to the console? What I'd like to do is to have
    @-codes, etc. interpreted in a string and save that string so I can
    then pass that string to printf() so I can specify a field length for
    the text.

    I think you're looking for bbs.atcode().

    That said, Synchronet @-codes already support a method for length field specification as well as left and rigth justification: http://wiki.synchro.net/custom:atcodes#formatting

    I think he's looking to get the entire value of the string with
    multiple translated at-codes combined, and possibly even other text, which @-code formatting does not work on. On a singular one, the formatting would work, but combined with others, not so much. :)

    ---
    [Psi-Jack -//- Decker]
    Synchronet Decker's Heaven -//- bbs.deckersheaven.com
  • From Nightfox@VERT/DIGDIST to Psi-Jack on Thursday, October 02, 2014 07:29:35
    Re: console.putmsg alternative that returns a string
    By: Psi-Jack to Nightfox on Thu Oct 02 2014 08:23:32

    text = text.replace(/@([^@]+)@/g, function(m, code) {
    return bbs.atcode(code);
    });

    Hmm, yeah. I don't think there's anything else. This text.replace itself goes through each beginning and ending @ code block and translates each one, at least as far as I can tell it does. the variable, text, becomes the full at-code translated result.

    Yep, I've used JavaScript's string replace() function in some of my scripts. And regular expressions are awesome.

    Nightfox

    ---
    Synchronet Digital Distortion BBS - digitaldistortionbbs.com
  • From Nightfox@VERT/DIGDIST to Psi-Jack on Sunday, October 05, 2014 09:51:55
    Re: console.putmsg alternative that returns a string
    By: Psi-Jack to Nightfox on Wed Oct 01 2014 09:32:55

    text = text.replace(/@([^@]+)@/g, function(m, code) {
    return bbs.atcode(code);
    });

    That seems to work well. I'm curious, how did you find that you could use an anonymous function for the replacement value in the JavaScript string replace() method? I've often referred to the w3schools.com JavaScript documentation, and their documentation for the string replace() method seems to imply that it expects a string for the replacement value: www.w3schools.com/jsref/jsref_replace.asp

    Nightfox

    ---
    Synchronet Digital Distortion BBS - digitaldistortionbbs.com
  • From Psi-Jack@VERT/DECKHVN2 to Nightfox on Monday, October 06, 2014 15:27:46
    Re: console.putmsg alternative that returns a string
    By: Nightfox to Psi-Jack on Sun Oct 05 2014 09:51 am

    Re: console.putmsg alternative that returns a string
    By: Psi-Jack to Nightfox on Wed Oct 01 2014 09:32:55

    text = text.replace(/@([^@]+)@/g, function(m, code) {
    return bbs.atcode(code);
    });

    That seems to work well. I'm curious, how did you find that you could use an anonymous function for the replacement value in the JavaScript string replace() method? I've often referred to the w3schools.com JavaScript documentation, and their documentation for the string replace() method seems to imply that it expects a string for the replacement value: www.w3schools.com/jsref/jsref_replace.asp

    Well, I didn't.. This is just stuff Deuce came up with for the newuser_signup.js I've been testing. ;)

    ---
    [Psi-Jack -//- Decker]
    Synchronet Decker's Heaven -//- bbs.deckersheaven.com
  • From Nightfox@VERT to Psi-Jack on Monday, October 06, 2014 12:47:50
    text = text.replace(/@([^@]+)@/g, function(m, code) {
    return bbs.atcode(code);
    });

    That seems to work well. I'm curious, how did you find that you
    could
    use an anonymous function for the replacement value in the
    JavaScript
    string replace() method? I've often referred to the w3schools.com JavaScript documentation, and their documentation for the string replace() method seems to imply that it expects a string for the replacement value: www.w3schools.com/jsref/jsref_replace.asp

    Well, I didn't.. This is just stuff Deuce came up with for the newuser_signup.js I've been testing. ;)

    Ah, I see.
    I tried the code that you shared, and I think it might need some more
    tweaking, as it seems it will replace text around a @ even if it's not a valid Synchronet @-code..

    Nightfox

    ---
    Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net
  • From Deuce@VERT/SYNCNIX to Nightfox on Monday, October 06, 2014 14:38:12
    Re: console.putmsg alternative that returns a string
    By: Nightfox to Psi-Jack on Sun Oct 05 2014 09:51 am

    That seems to work well. I'm curious, how did you find that you could use an anonymous function for the replacement value in the JavaScript string replace() method? I've often referred to the w3schools.com JavaScript documentation, and their documentation for the string replace() method
    seems to imply that it expects a string for the replacement value: www.w3schools.com/jsref/jsref_replace.asp

    http://www.synchro.net/docs/js/ref

    Specifically: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Object
    s/String/replace#Specifying_a_function_as_a_parameter


    ---
    http://DuckDuckGo.com/ a better search engine that respects your privacy.
    Synchronet My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Deuce@VERT/SYNCNIX to Nightfox on Monday, October 06, 2014 14:39:36
    Re: console.putmsg alternative that returns a string
    By: Nightfox to Psi-Jack on Mon Oct 06 2014 12:47 pm

    I tried the code that you shared, and I think it might need some more tweaking, as it seems it will replace text around a @ even if it's not a valid Synchronet @-code..

    It replaces everything between two @s, so two e-mail addresses would get borked
    and merged for example.

    ---
    http://DuckDuckGo.com/ a better search engine that respects your privacy.
    Synchronet My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Psi-Jack@VERT/DECKHVN2 to Deuce on Tuesday, October 07, 2014 11:23:29
    Re: console.putmsg alternative that returns a string
    By: Nightfox to Psi-Jack on Mon Oct 06 2014 12:47 pm

    I tried the code that you shared, and I think it might need some more tweaking, as it seems it will replace text around a @ even if it's not a valid Synchronet @-code..

    It replaces everything between two @s, so two e-mail addresses would get borked and merged for example.

    Yikes! Yeah.. That could definitely be bad..

    ---
    [Psi-Jack -//- Decker]
    Synchronet Decker's Heaven -//- bbs.deckersheaven.com
  • From Psi-Jack@VERT/DECKHVN2 to Deuce on Tuesday, October 07, 2014 14:47:24
    Re: Re: console.putmsg alternative that returns a string
    By: Psi-Jack to Deuce on Tue Oct 07 2014 11:23 am

    Re: console.putmsg alternative that returns a string
    By: Nightfox to Psi-Jack on Mon Oct 06 2014 12:47 pm

    I tried the code that you shared, and I think it might need some
    more tweaking, as it seems it will replace text around a @ even if
    it's not a valid Synchronet @-code..

    It replaces everything between two @s, so two e-mail addresses would
    get borked and merged for example.

    Yikes! Yeah.. That could definitely be bad..

    Quite bad. Yeah.

    ---
    [Psi-Jack -//- Decker]
    Synchronet Decker's Heaven -//- bbs.deckersheaven.com
  • From Nightfox@VERT/DIGDIST to Deuce on Tuesday, October 07, 2014 19:38:13
    Re: console.putmsg alternative that returns a string
    By: Deuce to Nightfox on Mon Oct 06 2014 14:38:12

    http://www.synchro.net/docs/js/ref

    Specifically: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global
    _Object s/String/replace#Specifying_a_function_as_a_parameter

    I see. Thanks for the links.

    Nightfox

    ---
    Synchronet Digital Distortion BBS - digitaldistortionbbs.com