If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Editing RubyEdit class
24 posts
• Page 1 of 3 • 1, 2, 3
Editing RubyEdit class
I noticed in the Flowstone install folder there is an fsm file called "system" in this schematic is a Ruby component that defines the RubyEdit class. I was thinking could we not alter this class to add line numbers ect?
I have played about with it a bit changing a few things in the syntax colouring ect, but couldn't get any line numbering going.
Can someone else that is fluent in Ruby see if that can be done?
Cheers,
Exo
I have played about with it a bit changing a few things in the syntax colouring ect, but couldn't get any line numbering going.
Can someone else that is fluent in Ruby see if that can be done?
Cheers,
Exo
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Editing RubyEdit class
yes it should work with codeRay
this shows how to get the line numbers
but i don't know hoe to put them in?
http://coderay.rubychan.de/
this shows how to get the line numbers
- Code: Select all
CodeRay.scan("5.times do\n puts 'Hello, world!'\nend", :ruby).div(:line_numbers => :table)
but i don't know hoe to put them in?
http://coderay.rubychan.de/
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
Thanks.
Seems div is outputing HTML which will be why it doesn't work.
I have tried modifying a few things but no luck....
Seems div is outputing HTML which will be why it doesn't work.
I have tried modifying a few things but no luck....
- Code: Select all
require "coderay"
class RubyEdit
Black = invertedColours ? [255,255,255] : [0,0,0]
Brown = [128,64,0]
Red = [163,20,20]
Blue = [0,0,255]
Green = [0,128,0]
Pink = [200,0,200]
Gold = [128,128,0]
Purple = [100,0,200]
Grey50 = [128,128,128]
Silver = [100,100,64]
def parse v,f
sourceLines = Array.new
v.each_line {|s| sourceLines.push s}
startIndex=0
lineStartIndeces=[0]
startIndex=v.index("\n",0)
while startIndex
lineStartIndeces<<(startIndex+1)
startIndex=v.index("\n",startIndex+2)
end
v.force_encoding "utf-8"
tp=CodeRay.scan(v,:ruby).div(:line_numbers => :table) #Doesn't work it outputs HTML
lines=[]
nLines=sourceLines.count
nLines.times {lines<<[]}
ci=0
strings=[]
types=[]
tp.each_with_index do |t,i|
if i.even? then strings<<t end
if i.odd? then types<<t end
# Check for newlines inside the current string and split
# where necessary
if i.odd?
if t != :string && t != :space && strings.last.class == String
subs = strings.last.split("\n")
if subs.size > 0
s = strings.pop
t = types.pop
subs.each do |str|
if str.size > 0
strings<<str
types<<t
end
strings<<"\n"
types<<:space
end
if s.index("\n") != s.length-1
s = strings.pop
t = types.pop
end
end
end
end
end
ln=0
for i in 0..strings.count-1
item=[]
t=types[i]
s=strings[i]
if s.eql? "\n"
ln+=1
elsif t!=:space && s.class==String
i1=v.index(s,ci)
if i1
ci=i1+s.length
item<<i1-lineStartIndeces[ln]<<s.length<<t
if ln<nLines
lines[ln]<<item
end
end
end
end
# Set up colour scheme
m={ :ident=>Black,:delimeter=>Black,:operator=>Black,
:keyword=>Blue,:class=>Pink,:method=>Black,:comment=>Green,
:class_variable=>Gold,:instance_variable=>Gold,:global_variable=>Silver,
:symbol=>Grey50,:constant=>Pink,
:integer=>Red,:float=>Red,:char=>Red,:content=>Red,:string=>Pink,
:regexp=>Black,:shell=>Black,:schematic=>Purple }
# Set up our own commands
schemCmds = ["output","input","watch","releaseMouse","captureMouse",
"redraw","time","parent","caption","alert","showCursor"]
li=0
# Colour the lines
lines.each do |l|
f.newLine
os = 0
if li < sourceLines.size
len = sourceLines[li].chomp.length
end
l.each do |i|
t=i[2]
# Check if we ran onto another line (due to a line continuation '\')
if i[0]-os > len
f.endLine len
os += len+2
f.newLine
li+=1
if li < sourceLines.size
len = sourceLines[li].chomp.length
end
end
if (i[0]+i[1]-os-1) < len
if( t == :ident && schemCmds.include?(sourceLines[li][(i[0]-os)..(i[0]-os+i[1]-1)]) )
t = :schematic
end
f.addSection i[0]-os,i[0]-os+i[1]-1,m[t]
end
end
f.endLine len
li+=1
end
end
end
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Editing RubyEdit class
yes, it outputs html...
i think the main problem is that codeRay is able to spitout line nrs, but what we need would be a nr table in the editor itself which would need to be an own area beside the editor area itself..
so we cannot add something to any v.source because it would distroy the code or?
i was thinking about to add a nr after each \n which doesn't affect the code behind - like only whats behind that is valid code - it but i`ve no idea if this would be possible?
i think the main problem is that codeRay is able to spitout line nrs, but what we need would be a nr table in the editor itself which would need to be an own area beside the editor area itself..
so we cannot add something to any v.source because it would distroy the code or?
i was thinking about to add a nr after each \n which doesn't affect the code behind - like only whats behind that is valid code - it but i`ve no idea if this would be possible?
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
Nubeat7 wrote:yes, it outputs html...
i think the main problem is that codeRay is able to spitout line nrs, but what we need would be a nr table in the editor itself which would need to be an own area beside the editor area itself..
so we cannot add something to any v.source because it would distroy the code or?
i was thinking about to add a nr after each \n which doesn't affect the code behind - like only whats behind that is valid code - it but i`ve no idea if this would be possible?
I don't know if it is possible everything I am currently trying breaks the code.
I have found a new class though LineFormat , that is the f variable.
I think it should be doable but currently I am struggling to understand the code and so I cannot say for definite.
Edit... I actually yes I think you are right, I don't think it is possible because adding extra characters would break the code that is passed to the interpreter.
Was a nice idea though I just didn't understand the code until now.
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Editing RubyEdit class
but would it be possible to show the actual code in an extra window including linenr?
i mean if we send self (from the window where some code is written) into another ruby module which just draws the code as text (including linenr) using coderay?
this would also be interesting for documetation as coderay enables you to filter out comments too, so you could generate a textfile which includes all the comments of your code.
i mean if we send self (from the window where some code is written) into another ruby module which just draws the code as text (including linenr) using coderay?
this would also be interesting for documetation as coderay enables you to filter out comments too, so you could generate a textfile which includes all the comments of your code.
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
I think that should be possible.
The coderay lines doesn't seem to work. To work we would need to copy the original code as a new string object and append the number to the beginning of each line manually and then this could be displayed.
The coderay lines doesn't seem to work. To work we would need to copy the original code as a new string object and append the number to the beginning of each line manually and then this could be displayed.
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Editing RubyEdit class
hmm, got some troubles with encoding to utf-8!?
here is a schematic of how i think it could work convert code into txt (if this ascii 8bit to utf-8 encoding would work)
this
.encode does scan input (v) to language(:ruby) and output to given format (:text) all in one, which i think should be the easiest way if i'm right with all that..
here is a schematic of how i think it could work convert code into txt (if this ascii 8bit to utf-8 encoding would work)
this
- Code: Select all
v.CodeRay.encode(v,:ruby,:text)
.encode does scan input (v) to language(:ruby) and output to given format (:text) all in one, which i think should be the easiest way if i'm right with all that..
- Attachments
-
- coderay1.fsm
- (725 Bytes) Downloaded 920 times
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
Exo wrote:To work we would need to copy the original code as a new string object and append the number to the beginning of each line manually and then this could be displayed.
Yes, and there is a sneaky way to do it.
Systems are down at home at the moment for some home improvements, but I have it working and can post later.
The trick is to hijack a RubyEdit method called "parse" - it gets called every time the code is edited. IIRC, I intercepted the input arguments by doing something like this...
- Code: Select all
def parse(*args, &block)
@code_string = args[0] # May not be the right index!
super(*args, &block) # Hand control back to the original method
end
@Exo - take a look in the code tracer prototype I sent you. it is in there somewhere.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Editing RubyEdit class
Nubeat7 wrote:hmm, got some troubles with encoding to utf-8!?
here is a schematic of how i think it could work convert code into txt (if this ascii 8bit to utf-8 encoding would work)
this
also only works if you include the encoders folder form the original coderay zip file into the flowstone ruby folder:..ruby/libraries/syntax/coderay !! which is not included in FS
- Code: Select all
v.CodeRay.encode(v,:ruby,:text)
.encode does scan input (v) to language(:ruby) and output to given format (:text) all in one, which i think should be the easiest way if i'm right with all that..
Nice Idea but the encoding cannot work because the RubyEdit is it's own object it isn't a String object and so cannot be encoded.
That file crashes flowstone here if I double click the file instead of opening it inside FS.
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
24 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 60 guests