Re: [code] Improved File Browser

From: Alexander Misel <alexander_misel.att.live.cn>
Date: Thu, 11 Oct 2018 03:37:32 +0000

Now I am looking forward to a feature that locks a view to only have ONE buffer (i.e. File Browser, TODO list). Any sugguestions on how to implement it?
________________________________
From: Alexander Misel <alexander_misel.att.live.cn>
Sent: Thursday, October 11, 2018 8:37
To: Mitchell; code.att.foicica.com
Subject: Re: [code] Improved File Browser

Thank you for you help. I updated the wiki and uploaded the file to https://foicica.com/wiki/ta-filebrowser/file/init.lua
________________________________
From: Mitchell <m.att.foicica.com>
Sent: Wednesday, October 10, 2018 20:46
To: code.att.foicica.com
Subject: Re: [code] Improved File Browser

Hi Alexander,

On Tue, 9 Oct 2018, Alexander Misel wrote:

> I found not so easy to solve the issues. As I placed a print(name) after the last buffer:set_styling but the print is fine, while the text is not colored. The second issue I tried the BUFFER_AFTER_SWITCH event, but I don't know how to color the text, simply copying the code from print_listing doesn't work.

Sorry about that. I cannot figure out why the last directory is not highlighted either :( This simple BUFFER_AFTER_SWITCH event highlights directories:

   events.connect(events.BUFFER_AFTER_SWITCH, function()
     if not (buffer._type or ''):match('^%[File Browser') then return end
     for i = 0, buffer.line_count - 1 do
       local line = buffer:get_line(i)
       if line:find('[/\\][\r\n]*$') then
         buffer:start_styling(buffer:position_from_line(i), 0xFF)
         buffer:set_styling(#line, M.styles.directory)
       end
     end
   end)

If you wanted to also highlight links and sockets correctly, you'd probably want to call `get_path()` for each line number and then call `lfs.attributes(path, 'mode')` to get the mode to use with `M.styles`.

The file browser was originally designed to be a dedicated split view, which is why I didn't bother supporting BUFFER_AFTER_SWITCH highlight-restoring.

Cheers,
Mitchell

--
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Wed 10 Oct 2018 - 23:37:32 EDT

This archive was generated by hypermail 2.2.0 : Thu 11 Oct 2018 - 06:49:39 EDT