sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Textarea line separators on Mac

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 2 Posters 311 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      MartinRinehart
      last edited by

      My PC <textarea> lines are separated by crlf: 13, 10. Does anyone know what that is on a Mac?

      In the following script, Ruby launches a WebDialog with a text area with two lines ("one" and "two"). The WebDialog calls Ruby after it is loaded. The Ruby callback grabs the text area's value, and writes it to the console, one number per character. The separator(s) will appear between 101 ("e") and 116 ("t").

      Thank you!

      
      # ta_sep.rb 
      
      require 'sketchup'
      
      html="
      <html> <body>
      
      <textarea id='ta'>one
      two</textarea>
      
      <script>
          onload = function() { location = 'skp;go'; }
      </script>
      
      </body> </html>"
      
      wd = UI;;WebDialog.new( "Test", true, "test", 400, 300, 100, 100, true )
      wd.set_html( html )
      
      wd.add_action_callback( "go" ) do | dlg, msg |
          val = wd.get_element_value( 'ta' )
          for i in 1..val.length do puts val[i-1] end
      end
      
      wd.show()
      
      

      wd.jpg

      rc.jpg

      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

      1 Reply Last reply Reply Quote 0
      • M Offline
        MartinRinehart
        last edited by

        Anyone?

        Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

        1 Reply Last reply Reply Quote 0
        • T Offline
          todd burch
          last edited by

          You're welcome!

          Todd


          SketchUp001.jpg

          1 Reply Last reply Reply Quote 0
          • T Offline
            todd burch
            last edited by

            Any now my question.

            Why are you coding at that level? Why not just bust the input data up into ruby "newlines"?

            1 Reply Last reply Reply Quote 0
            • M Offline
              MartinRinehart
              last edited by

              @unknownuser said:

              You're welcome!

              Thank you!

              @unknownuser said:

              Why are you coding at that level?

              Stupidity or ignorance. Maybe both.

              @unknownuser said:

              Why not just bust the input data up into ruby "newlines"?

              Hmmm. This is the code that gets a WebDialog <textarea>'s data into a disk file:

              
                  # write the file
                  str = wd_console.get_element_value( 'console' )
                  str.gsub!( /\r\n/, "\n" ) # why? doesn't look PC, but it works
                  file = File.new( pathname, 'w' )
                  file.puts( str )
                  file.close()
              
              

              I'm thinking that will work fine on a Mac, because the gsub!() will find zero occurrences. Now the other direction: you read the file as a string and pass the string to the textarea and it will be Win/Mac compatible.

              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

              1 Reply Last reply Reply Quote 0
              • T Offline
                todd burch
                last edited by

                Unless the files you create on a Mac via this dialog will be moved over to Windows for the purpose of being read with Notepad (and this is only because Notepad is stupid), I personally see no productivity or functionality gains from bothering with each platforms newline patterns, unless you just want to.

                But heh, that's just me. 😆

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MartinRinehart
                  last edited by

                  @unknownuser said:

                  I personally see no productivity or functionality gains from bothering with each platforms newline patterns, unless you just want to.

                  This isn't the file I want given the input textarea:

                  two.jpg

                  You have to convert crlf to newline because Ruby converts newline to crlf as it writes the file on a PC. Ugh.

                  
                  # ta_sep.rb 
                  
                  require 'sketchup'
                  
                  html="
                  <html> <body>
                  
                  <textarea id='ta'>one
                  two</textarea>
                  
                  <script>
                      onload = function() { location = 'skp;go'; }
                  </script>
                  
                  </body> </html>"
                  
                  wd = UI;;WebDialog.new( "Test", true, "test", 400, 300, 100, 100, true )
                  wd.set_html( html )
                  
                  wd.add_action_callback( "go" ) do | dlg, msg |
                      val = wd.get_element_value( 'ta' )
                      # val.gsub!( /\r\n/, "\n" )
                      pn = UI.savepanel( 
                          "Save As ...", File.dirname(__FILE__), 't.txt' )
                      file = File.new( pn, 'w' )
                      file.puts( val )
                      file.close()
                  end
                  
                  wd.show()
                  
                  
                  

                  I think this is correct cross-platform code if you uncomment the gsub!(). For this I be thanking you and Notepad++ (View/Show Symbol/Show All Characters).

                  Ruby's lovely ability to handle everything with newlines, platform-independently, does not extend to text read from a browser's textarea widgets.

                  Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement