The Accidental Rubyist

invalid byte sequence in UTF-8

Update on trestle/rails

leave a comment »

The creator of trestle is a very helpful and prompt person. That’s great news as trestle approaches 1.0.

Trestle, a flexible, modern admin framework for Ruby on Rails, is https://trestle.io/. Feel free to explore more about Trestle and its features on their website.

I also found some nice free icons at https://iconify.design. SVG format, no downloading, or installing, or gems required. Just copy the SVG code into your partial. You can customise also before copying the code.

Written by totalrecall

July 22, 2023 at 10:21 am

Posted in Rails, ruby

Tagged with ,

Trestle (Admin) for Rails — no documentation

leave a comment »

(June 2023) I’ve been trying out various admin gems / frameworks for ruby on rails. These include avo, madmin, bullet-train and recently trestle.

Trestle is very good, it creates very clean, attractive screens with tabs and sidebars. It uses bootstrap unlike most of the others which use tailwind. You can use it with postgres or sqlite but I think postgres would be better since the search and other add-on gems use postgres, especially search.

However, there is surprisingly one big stumbling block to Trestle. It has no documentation. Or the demo application is the documentation. You have to sift through the demo, or grep/ag/rg through the gem’s source to figure things out.

That’s not exactly something that is going to help people on-board it. However, I’d hate to leave this without sticking around for a little longer. I don’t know how much customization is possible. I guess I’ll get back on this in a week by which time I hope to decide whether to continue.

That way, in comparison Avo has very good documentation and their developer Adrian Marin helps out very quickly.

Let’s say I have a table/index view in Avo for posts. Each post contains an author (which links to the author table). Avo uses the ransack gem. I can easily sort the table/index view on the author. In trestle, this is a tad more complicated, and should not be since this is a standard requirement. Or let’s say my index view of authors shows the count of books. I should be able to sort on the count of books. This is easy in Avo, but I’ve not been able to figure out how to do this in trestle.

That said I am still loving the way I can organize the form, make tabs, sections, sidebars with trestle.

That said trestle is at 0.9.8, so hopefully by version 1, we’ll have some good documentation.

I’ll update this in a week after some more work.

EDIT: The creator of trestle has been extremely helpful and answers queries immediately. I’ve been able to sort out a couple issues like the above instantly. Look forward to working more with it in the next week.

Written by totalrecall

July 2, 2023 at 11:03 pm

Posted in Rails, ruby

Tagged with ,

rbcurse continues as “canis”

leave a comment »

rbcurse will only have bug-fixes in it. rbcurse has a tutorial on github, too.

The code has been taken over by Canis (on github and available as a gem). Canis has removed a lot of stuff, and changed things too, 

Please move onto Canis if you are interested. Canis is NOT backward compatible with rbcurse.

 

Written by totalrecall

August 30, 2014 at 11:09 pm

Posted in Uncategorized

rbcurse no longer maintained

with 2 comments

Due to serious family issues, I will no longer be able to maintain rbcurse or other gems.

They may be taken over, or used as-is. I will continue to receive emails or comments left on this site, and will answer as soon as i can.

Sorry for the inconvenience. I will try to create a proper tutorial for rbcurse-core as a github project since I am unable to update the rubyforge tutorial due to a “Permission denied (publickey,gssapi-keyex,gssapi-with-mic)”. However, the best way of getting started is to see the examples in the examples folder of the project.

Written by totalrecall

March 15, 2014 at 2:21 pm

Posted in ruby

The Future of rbcurse (ruby ncurses)

with 14 comments

A year back I had split rbcurse into rbcurse-core and extras and experimental. Of late, I have been working on a widget called *textpad* to replace textview. It uses pads (which i earlier abhored and avoided) and this really simplifies the logic. I have also used the same textpad as a list, so that now obviates having a separate list class (unless I need to do multiple selection).
I have tested textpad as a textview and a list and a popup in a gem called cygnus. It is the ncurses version of the cetus gem which uses the terminal (I actually use cetus, cygnus is mostly to test out textpad).

I am also working on a replacement for tabular_widget using the same textpad. It extends textpad and only adds a minimal amount of code, but allows most of what tabular_widget allowed, while making it easier to override the rendering. I will release it after using it a little more in my current project. That mostly leaves replacing tree with a pad version.

However, my issue then is how to release these. I could replace the old widgets, but that won’t be backward compatible, and I have made things simpler, so i cannot be totally backward compatible. I could add these to the current project and request people to move over to these new widgets. I could release these as a separate gem….

My next goal after that is to seriously trim down the base. That is form and widget, and also Window, utils etc. This will definitely break everything and require a new gem. There is a lot of stuff that makes the base complex but may never be used. There is also code that really needs a rewrite such as Button and Menu.

Written by totalrecall

April 10, 2013 at 5:22 pm

Posted in ruby

indenting zsh files in vim

leave a comment »

Currently, if you start a function with the function keyword, the function body is not indented. The following line (added the last OR condition) will result in functions being indented.

elseif line =~ ‘^\s*\<\k\+\>\s*()\s*{‘ || line =~ ‘^\s*{‘ || line =~ ‘^\s*function ‘

Not sure whom to contact to get this fixed, or else each update will result in the change being overwritten.

Written by totalrecall

January 13, 2013 at 5:20 pm

Posted in ruby

zfm : fast file selection and directory navigation (zsh/commandline)

with 2 comments

I’ve just uploaded a zsh script for fast navigation, file selection etc. Try it out and give me feedback.

Command-line junkies should appreciate this.

https://github.com/rkumar/zfm
zfm
Please submit it to Reddit or Hacker News if you like it.

Written by totalrecall

December 25, 2012 at 3:41 pm

Posted in unix, unixscript, zsh

Auto-update timestamp in files upon Save

with one comment

If you use vim for editing files, you can stick this in your vimrc file, so whenever you save the file, "Last update" gets updated with the current time. If you enhance this script, pls let me know, so we can all benefit.

This requirement is already met by timestamp.vim, but that’s a biggish plugin, and does a lot of other updates, and I just wanted a few lines in my vimrc, and only timestamp updated.

https://gist.github.com/4166881

" auto-update last update if there's a update tag
autocmd! BufWritePre * :call s:timestamp()
" to update timestamp when saving if its in the first few lines of a file
function! s:timestamp()
let pat = '\(Last update\s*:\s*\).*'
let rep = '\1' . strftime("%Y-%m-%d %H:%M")
call s:subst(1, 5, pat, rep)
endfunction
" subst taken from timestamp.vim
" {{{1 subst( start, end, pat, rep): substitute on range start - end.
function! s:subst(start, end, pat, rep)
let lineno = a:start
while lineno <= a:end
let curline = getline(lineno)
if match(curline, a:pat) != -1
let newline = substitute( curline, a:pat, a:rep, '' )
if( newline != curline )
" Only substitute if we made a change
"silent! undojoin
keepjumps call setline(lineno, newline)
endif
endif
let lineno = lineno + 1
endwhile
endfunction

" }}}1

Written by totalrecall

November 29, 2012 at 10:30 am

Posted in vim

rbcurse-extras 0.0.0 released

with 9 comments

Finally managed to release rbcurse-extras initial version with a small tweak to vimsplit. I also did some work on Actions for widgets so using ":" or "M-:" could pop up a menu for the current widget. Applications can add to this. This led to upgrades in rbcurse-core, so i’ve released rbcurse-core-0.0.3 with those changes.

I’ve tested out only editable lists and tables (the old programs) in rbcurse-extras, not everything.

The previous version of rbcurse (0.0.2), allows the user to see key-bindings for the current widget/control by pressing "M-?" or "?". It allows user to edit a textbox in vim or EDITOR and also "save as" using the ":"/"M-:" menu. It also introduced History to Field (optional at present), so you need to extend the Field object. History can be popped up using "M-h". I’ve used this in the shell-output dialog.

I’ve done some changes to ncurses settings (cbreak and half-delay) as i found that pressing C-c repeatedly quickly was crashing the app (see earlier posts), Hope this holds up in all cases.

Written by totalrecall

January 5, 2012 at 1:35 pm

Posted in ncurses, rbcurse, ruby

TIL: ncurses cbreak and halfdelay

leave a comment »

I accidentally typed C-c quickly in a sample of rbcurse and found that the program crashed giving an error somewhere deep in logger. I repeated this in various programs, the line giving the error would be random. I tried various versions of ruby, wondered whether this had started happening after upgrading to Lion, or perhaps a bug in ffi-ncurses, or something with iTerm2, or maybe xterm-256color.

(I might add, that when i do a wgetch or getch in my app, there is "rescue Interrupt" clause to take care of this situation.)

After many hours, I finally found that if I press C-c slowly one after the other, my app takes it, but in quick succession, the 3rd or 4th causes the program to abort. After further research, i came down to the following:

1. using cbreak in ncurses causes successive Control-C’s to be taken as interrupts.
2. Using half-delay also puts ncurses back into cbreak mode.

I was using half-delay so that some complex key codes can be handled, and this includes using ESC in place of ALT/META. So pressing ESC followed by ‘w’ in quick succession is taken as ALT-w and not 2 key strokes.

Currently my working solution has been to comment off cbreak, and to use nodelay in place of halfdelay. It seems to be working as of now. No idea whether there is some key under some terminal that may fail. I have tested this out under many different TERMs and stuff. I hope this doesn’t make the application hog CPU.

Update: I cannot set nodelay in startup as this means that wherever in the application I might do a getch, it will be non-blocking and I will not get the key I am expecting. I found this while typing “gg” in a textview. So I have used a wtimeout and set it to 1000 for the meantime. Switching off nodelay by itself does not work for me since in my app, when the window gets an ESC it waits for the next character or ERR to see if its an Esc-alphabet.

Written by totalrecall

December 20, 2011 at 12:03 pm

Posted in ruby