1 -- Luakit configuration file, more information at http://luakit.org/
7 -- Widget construction aliases
8 function eventbox() return widget
{type="eventbox"} end
9 function hbox() return widget
{type="hbox"} end
10 function label() return widget
{type="label"} end
11 function notebook() return widget
{type="notebook"} end
12 function vbox() return widget
{type="vbox"} end
13 function webview() return widget
{type="webview"} end
14 function window() return widget
{type="window"} end
15 function entry() return widget
{type="entry"} end
17 -- Variable definitions
18 HOMEPAGE
= "http://luakit.org/"
19 --HOMEPAGE = "http://github.com/mason-larobina/luakit"
22 MAX_SRCH_HISTORY
= 100
23 --HTTPPROXY = "http://example.com:3128"
25 -- Setup download directory
26 DOWNLOAD_DIR
= luakit
.get_special_dir("DOWNLOAD") or (os
.getenv("HOME") .. "/downloads")
31 font
= "monospace normal 9",
36 statusbar_fg
= "#fff",
37 statusbar_bg
= "#000",
42 loaded_fg
= "#33AADD",
45 selected_tablabel_fg
= "#fff",
46 selected_tablabel_bg
= "#000",
48 -- Enforce a minimum tab width of 30 characters to prevent longer tab
49 -- titles overshadowing small tab titles when things get crowded.
50 tablabel_format
= "%-30s",
53 widget
.add_signal("new", function (wi
)
54 wi
:add_signal("init", function (wi
)
55 if wi
.type == "window" then
56 wi
:add_signal("destroy", function ()
57 -- Call the quit function if this was the last window left
58 if #luakit
.windows
== 0 then luakit
.quit() end
66 google
= "http://google.com/search?q={0}",
67 imdb
= "http://imdb.com/find?s=all&q={0}",
68 sourceforge
= "http://sf.net/search/?words={0}",
71 -- Add key bindings to be used across all windows
73 -- bind.buf(Pattern, function (w, buffer, opts) .. end, opts),
74 -- bind.key({Modifiers}, Key name, function (w, opts) .. end, opts),
75 -- bind.but({Modifiers}, Button Number, function (w, opts) .. end, opts),
77 bind
.key({}, "Escape", function (w
) w
:set_mode() end),
78 bind
.key({"Control"}, "[", function (w
) w
:set_mode() end),
81 bind
.but({}, 2, function (w
)
82 -- Open hovered uri in new tab
83 local uri
= w
:get_current().hovered_uri
84 if uri
then w
:new_tab(uri
)
85 else -- Open selection in current tab
86 uri
= luakit
.selection()
87 if uri
then w
:get_current().uri
= uri
end
90 bind
.but({}, 8, function (w
) w
:back() end),
91 bind
.but({}, 9, function (w
) w
:forward() end),
94 bind
.key({}, "i", function (w
) w
:set_mode("insert") end),
95 bind
.key({}, ":", function (w
) w
:set_mode("command") end),
98 bind
.key({}, "h", function (w
) w
:scroll_horiz("-"..SCROLL_STEP
.."px") end),
99 bind
.key({}, "j", function (w
) w
:scroll_vert ("+"..SCROLL_STEP
.."px") end),
100 bind
.key({}, "k", function (w
) w
:scroll_vert ("-"..SCROLL_STEP
.."px") end),
101 bind
.key({}, "l", function (w
) w
:scroll_horiz("+"..SCROLL_STEP
.."px") end),
102 bind
.key({}, "Left", function (w
) w
:scroll_horiz("-"..SCROLL_STEP
.."px") end),
103 bind
.key({}, "Down", function (w
) w
:scroll_vert ("+"..SCROLL_STEP
.."px") end),
104 bind
.key({}, "Up", function (w
) w
:scroll_vert ("-"..SCROLL_STEP
.."px") end),
105 bind
.key({}, "Right", function (w
) w
:scroll_horiz("+"..SCROLL_STEP
.."px") end),
106 bind
.buf("^gg$", function (w
) w
:scroll_vert("0%") end),
107 bind
.buf("^G$", function (w
) w
:scroll_vert("100%") end),
108 bind
.buf("^[\-\+]?[0-9]+[%%G]$", function (w
, b
) w
:scroll_vert(string.match(b
, "^([\-\+]?%d+)[%%G]$") .. "%") end),
111 bind
.key({}, "p", function (w
) w
:navigate(luakit
.selection()) end),
112 bind
.key({}, "P", function (w
) w
:new_tab(luakit
.selection()) end),
115 bind
.buf("^o$", function (w
, c
) w
:enter_cmd(":open ") end),
116 bind
.buf("^t$", function (w
, c
) w
:enter_cmd(":tabopen ") end),
117 bind
.buf("^,g$", function (w
, c
) w
:enter_cmd(":websearch google ") end),
120 bind
.key({}, "/", function (w
) w
:start_search(true) end),
121 bind
.key({}, "?", function (w
) w
:start_search(false) end),
122 bind
.key({}, "n", function (w
) w
:search(nil, true) end),
123 bind
.key({}, "N", function (w
) w
:search(nil, false) end),
126 bind
.buf("^[0-9]*H$", function (w
, b
) w
:back (tonumber(string.match(b
, "^(%d*)H$") or 1)) end),
127 bind
.buf("^[0-9]*L$", function (w
, b
) w
:forward(tonumber(string.match(b
, "^(%d*)L$") or 1)) end),
130 bind
.buf("^[0-9]*gT$", function (w
, b
) w
:prev_tab(tonumber(string.match(b
, "^(%d*)gT$") or 1)) end),
131 bind
.buf("^[0-9]*gt$", function (w
, b
) w
:next_tab(tonumber(string.match(b
, "^(%d*)gt$") or 1)) end),
132 bind
.buf("^gH$", function (w
) w
:new_tab(HOMEPAGE
) end),
133 bind
.buf("^d$", function (w
) w
:close_tab() end),
135 bind
.key({}, "r", function (w
) w
:reload() end),
136 bind
.buf("^gh$", function (w
) w
:navigate(HOMEPAGE
) end),
137 bind
.buf("^ZZ$", function (w
) luakit
.quit() end),
140 bind
.key({}, "f", function (w
) w
:set_mode("follow") end),
144 bind
.key({"Shift"}, "Insert", function (w
) w
:insert_cmd(luakit
.selection()) end),
145 bind
.key({}, "Up", function (w
) w
:cmd_hist_prev() end),
146 bind
.key({}, "Down", function (w
) w
:cmd_hist_next() end),
147 bind
.key({}, "Tab", function (w
) w
:cmd_completion() end),
148 bind
.key({"Control"}, "w", function (w
) w
:del_word() end),
149 bind
.key({"Control"}, "u", function (w
) w
:del_line() end),
152 bind
.key({}, "Up", function (w
) w
:srch_hist_prev() end),
153 bind
.key({}, "Down", function (w
) w
:srch_hist_next() end),
160 -- bind.cmd({Command, Alias1, ...}, function (w, arg, opts) .. end, opts),
161 bind
.cmd({"open", "o" }, function (w
, a
) w
:navigate(a
) end),
162 bind
.cmd({"tabopen", "t" }, function (w
, a
) w
:new_tab(a
) end),
163 bind
.cmd({"back" }, function (w
, a
) w
:back(tonumber(a
) or 1) end),
164 bind
.cmd({"forward", "f" }, function (w
, a
) w
:forward(tonumber(a
) or 1) end),
165 bind
.cmd({"scroll" }, function (w
, a
) w
:scroll_vert(a
) end),
166 bind
.cmd({"quit", "q" }, function (w
) luakit
.quit() end),
167 bind
.cmd({"close", "c" }, function (w
) w
:close_tab() end),
168 bind
.cmd({"websearch", "ws"}, function (w
, e
, s
) w
:websearch(e
, s
) end),
169 bind
.cmd({"reload", }, function (w
) w
:reload() end),
172 function set_http_options(w
)
173 local proxy
= HTTPPROXY
or os
.getenv("http_proxy")
174 if proxy
then w
:set('proxy-uri', proxy
) end
175 w
:set('user-agent', 'luakit')
176 -- Uncomment the following options if you want to enable SSL certs validation.
177 -- w:set('ssl-ca-file', '/etc/certs/ca-certificates.crt')
178 -- w:set('ssl-strict', true)
181 -- Build and pack window widgets
182 function build_window()
183 -- Create a table for widgets and state variables for a window
195 -- Status bar widgets
199 -- Left aligned widgets
206 -- Fills space between the left and right aligned widgets
208 -- Right aligned widgets
227 w
.ebox
:set_child(w
.layout
)
228 w
.win
:set_child(w
.ebox
)
232 t
.ebox
:set_child(t
.layout
, false, false, 0)
233 w
.layout
:pack_start(t
.ebox
, false, false, 0)
236 w
.layout
:pack_start(w
.tabs
, true, true, 0)
238 -- Pack left-aligned statusbar elements
240 l
.layout
:pack_start(l
.uri
, false, false, 0)
241 l
.layout
:pack_start(l
.loaded
, false, false, 0)
242 l
.ebox
:set_child(l
.layout
)
244 -- Pack right-aligned statusbar elements
246 r
.layout
:pack_start(r
.buf
, false, false, 0)
247 r
.layout
:pack_start(r
.tabi
, false, false, 0)
248 r
.layout
:pack_start(r
.scroll
, false, false, 0)
249 r
.ebox
:set_child(r
.layout
)
251 -- Pack status bar elements
253 s
.layout
:pack_start(l
.ebox
, false, false, 0)
254 s
.layout
:pack_start(s
.filler
, true, true, 0)
255 s
.layout
:pack_start(r
.ebox
, false, false, 0)
256 s
.ebox
:set_child(s
.layout
)
257 w
.layout
:pack_start(s
.ebox
, false, false, 0)
261 i
.layout
:pack_start(i
.prompt
, false, false, 0)
262 i
.layout
:pack_start(i
.input
, true, true, 0)
263 i
.ebox
:set_child(i
.layout
)
264 w
.layout
:pack_start(i
.ebox
, false, false, 0)
267 i
.input
.show_frame
= false
268 w
.tabs
.show_tabs
= false
270 l
.uri
.selectable
= true
275 function attach_window_signals(w
)
276 -- Attach notebook widget signals
277 w
.tabs
:add_signal("page-added", function (nbook
, view
, idx
)
278 w
:update_tab_count(idx
)
279 w
:update_tab_labels()
282 w
.tabs
:add_signal("switch-page", function (nbook
, view
, idx
)
283 w
:update_tab_count(idx
)
284 w
:update_win_title(view
)
286 w
:update_progress(view
)
287 w
:update_tab_labels(idx
)
290 -- Attach window widget signals
291 w
.win
:add_signal("key-press", function (win
, mods
, key
)
292 -- Reset command line completion
293 if w
:get_mode() == "command" and key
~= "Tab" and w
.compl_start
then
298 if w
:hit(mods
, key
) then
303 w
.win
:add_signal("mode-changed", function (win
, mode
)
304 local i
, p
= w
.ibar
.input
, w
.ibar
.prompt
307 w
.cmd_hist_cursor
= nil
309 -- Clear following hints if the user exits follow mode
310 if w
.showing_hints
then
311 w
:eval_js("clear();");
312 w
.showing_hints
= false
315 -- If a user aborts a search return to the original position
316 if w
.search_start_marker
then
317 w
:get_current():set_scroll_vert(w
.search_start_marker
)
318 w
.search_start_marker
= nil
321 if mode
== "normal" then
324 elseif mode
== "insert" then
327 p
.text
= "-- INSERT --"
329 elseif mode
== "command" then
335 elseif mode
== "search" then
338 elseif mode
== "follow" then
339 w
:eval_js_from_file(util
.find_data("scripts/follow.js"))
340 w
:eval_js("clear(); show_hints();")
341 w
.showing_hints
= true
349 w
.ibar
.prompt
.text
= ""
350 w
.ibar
.input
.text
= ""
354 -- Attach inputbar widget signals
355 w
.ibar
.input
:add_signal("changed", function()
356 local text
= w
.ibar
.input
.text
357 -- Auto-exit "command" mode if you backspace or delete the ":"
358 -- character at the start of the input box when in "command" mode.
359 if w
:is_mode("command") and not string.match(text
, "^:") then
361 elseif w
:is_mode("search") then
362 if string.match(text
, "^[\?\/]") then
363 w
:search(string.sub(text
, 2), (string.sub(text
, 1, 1) == "/"))
368 elseif w
:is_mode("follow") then
369 w
:eval_js(string.format("update(%q)", w
.ibar
.input
.text
))
373 w
.ibar
.input
:add_signal("activate", function()
374 local text
= w
.ibar
.input
.text
375 if w
:is_mode("command") then
377 w
:match_cmd(string.sub(text
, 2))
379 elseif w
:is_mode("search") then
380 w
:srch_hist_add(text
)
381 w
:search(string.sub(text
, 2), string.sub(text
, 1, 1) == "/")
382 -- User doesn't want to return to start position
383 w
.search_start_marker
= nil
385 w
.ibar
.prompt
.text
= util
.escape(text
)
391 -- Attach signal handlers to a new tab's webview
392 function attach_webview_signals(w
, view
)
393 view
:add_signal("title-changed", function (v
)
394 w
:update_tab_labels()
395 if w
:is_current(v
) then
396 w
:update_win_title(v
)
400 view
:add_signal("property::uri", function (v
)
401 w
:update_tab_labels()
402 if w
:is_current(v
) then
407 view
:add_signal("link-hover", function (v
, link
)
408 if w
:is_current(v
) and link
then
409 w
.sbar
.l
.uri
.text
= "Link: " .. util
.escape(link
)
413 view
:add_signal("link-unhover", function (v
)
414 if w
:is_current(v
) then
419 view
:add_signal("form-active", function ()
423 view
:add_signal("root-active", function ()
427 view
:add_signal("key-press", function ()
428 -- Only allow key press events to hit the webview if the user is in
430 if not w
:is_mode("insert") then
435 view
:add_signal("button-release", function (v
, mods
, button
)
436 if w
:hit(mods
, button
) then
441 view
:add_signal("load-status", function (v
, status
)
442 if w
:is_current(v
) then
444 if status
== "provisional" then
450 -- 'link' contains the download link
451 -- 'mime' contains the mime type that is requested
452 -- return TRUE to accept or FALSE to reject
453 view
:add_signal("mime-type-decision", function (v
, link
, mime
)
454 if w
:is_current(v
) then
455 if luakit
.verbose
then print(string.format("Requested link: %s (%s)", link
, mime
)) end
457 -- i.e. block binary files like *.exe
458 if string.match(mime
, "application/octet-stream") then
464 -- 'link' contains the download link
465 -- 'filename' contains the suggested filename (from server or webkit)
466 view
:add_signal("download-request", function (v
, link
, filename
)
467 if w
:is_current(v
) and filename
then
469 os
.execute(string.format("mkdir -p %q", DOWNLOAD_DIR
))
471 local dl
= DOWNLOAD_DIR
.. "/" .. filename
472 local wget
= string.format("wget -q %q -O %q &", link
, dl
)
473 if luakit
.verbose
then print("Launching: " .. wget
) end
478 view
:add_signal("property::progress", function (v
)
479 if w
:is_current(v
) then
484 view
:add_signal("expose", function (v
)
485 if w
:is_current(v
) then
491 -- Parses scroll amounts of the form:
492 -- Relative: "+20%", "-20%", "+20px", "-20px"
493 -- Absolute: 20, "20%", "20px"
494 -- And returns an absolute value.
495 function parse_scroll(current
, max, value
)
496 if string.match(value
, "^%d+px$") then
497 return tonumber(string.match(value
, "^(%d+)px$"))
498 elseif string.match(value
, "^%d+%%$") then
499 return math
.ceil(max * (tonumber(string.match(value
, "^(%d+)%%$")) / 100))
500 elseif string.match(value
, "^[\-\+]%d+px") then
501 return current
+ tonumber(string.match(value
, "^([\-\+]%d+)px"))
502 elseif string.match(value
, "^[\-\+]%d+%%$") then
503 return math
.ceil(current
+ (max * (tonumber(string.match(value
, "^([\-\+]%d+)%%$")) / 100)))
505 print("E: unable to parse scroll amount:", value
)
509 -- Helper functions which operate on a windows widget structure
511 -- Return the widget in the currently active tab
512 get_current
= function (w
) return w
.tabs
:atindex(w
.tabs
:current()) end,
513 -- Check if given widget is the widget in the currently active tab
514 is_current
= function (w
, wi
) return w
.tabs
:indexof(wi
) == w
.tabs
:current() end,
516 -- Wrappers around the mode plugin
517 set_mode
= function (w
, name
) mode
.set(w
.win
, name
) end,
518 get_mode
= function (w
) return mode
.get(w
.win
) end,
519 is_mode
= function (w
, name
) return name
== w
:get_mode() end,
520 is_any_mode
= function (w
, t
, name
) return util
.table.hasitem(t
, name
or w
:get_mode()) end,
522 -- Wrappers around the view:get_prop & view:set_prop methods
523 get
= function (w
, prop
, view
)
524 if not view
then view
= w
:get_current() end
525 return view
:get_prop(prop
)
528 set
= function (w
, prop
, val
, view
)
529 if not view
then view
= w
:get_current() end
530 view
:set_prop(prop
, val
)
533 get_tab_title
= function (w
, view
)
534 if not view
then view
= w
:get_current() end
535 return view
:get_prop("title") or view
.uri
or "(Untitled)"
538 navigate
= function (w
, uri
, view
)
539 local v
= view
or w
:get_current()
543 return w
:new_tab(uri
)
547 reload
= function (w
, view
)
548 if not view
then view
= w
:get_current() end
552 new_tab
= function (w
, uri
)
553 local view
= webview()
556 attach_webview_signals(w
, view
)
557 if uri
then view
.uri
= uri
end
558 view
.show_scrollbars
= false
562 -- close the current tab
563 close_tab
= function (w
)
564 view
= w
:get_current()
565 if not view
then return end
571 -- evaluate javascript code and return string result
572 eval_js
= function (w
, script
, file
, view
)
573 if not view
then view
= w
:get_current() end
574 return view
:eval_js(script
, file
or "(buffer)")
577 -- evaluate javascript code from file and return string result
578 eval_js_from_file
= function (w
, file
, view
)
579 local fh
, err
= io
.open(file
)
580 if not fh
then return error(err
) end
581 local script
= fh
:read("*a")
583 return w
:eval_js(script
, file
, view
)
586 -- Wrapper around the bind plugin's hit method
587 hit
= function (w
, mods
, key
)
588 local caught
, newbuf
= bind
.hit(w
.binds
or {}, mods
, key
, w
.buffer
, w
:is_mode("normal"), w
)
594 -- Wrapper around the bind plugin's match_cmd method
595 match_cmd
= function (w
, buffer
)
596 return bind
.match_cmd(commands
, buffer
, w
)
599 -- enter command or characters into command line
600 enter_cmd
= function (w
, cmd
)
601 local i
= w
.ibar
.input
602 w
:set_mode("command")
607 -- insert a string into the command line at the current cursor position
608 insert_cmd
= function (w
, str
)
609 if not str
then return nil end
610 local i
= w
.ibar
.input
612 local pos
= i
:get_position()
613 local left
, right
= string.sub(text
, 1, pos
), string.sub(text
, pos
+1)
614 i
.text
= left
.. str
.. right
615 i
:set_position(pos
+ #str
+ 1)
618 -- search engine wrapper
619 websearch
= function (w
, args
)
620 local sep
= string.find(args
, " ")
621 local engine
= string.sub(args
, 1, sep
-1)
622 local search
= string.sub(args
, sep
+1)
623 if not search_engines
[engine
] then
624 print("E: No matching search engine found:", engine
)
627 local uri
= string.gsub(search_engines
[engine
], "{%d}", search
)
628 return w
:navigate(uri
)
631 -- Command line completion of available commands
632 cmd_completion
= function (w
)
633 local i
= w
.ibar
.input
634 local s
= w
.sbar
.l
.uri
637 -- Get last completion (is reset on key press other than <Tab>)
638 if not w
.compl_start
or w
.compl_index
== 0 then
639 w
.compl_start
= "^" .. string.sub(i
.text
, 2)
643 -- Get suitable commands
644 for _
, b
in ipairs(commands
) do
645 for _
, c
in pairs(b
.commands
) do
646 if c
and string.match(c
, w
.compl_start
) then
647 table.insert(cmpl
, c
)
656 for index
, comp
in pairs(cmpl
) do
657 if index
== w
.compl_index
then
658 i
.text
= ":" .. comp
.. " "
667 -- cycle through all possible completions
668 if w
.compl_index
== #cmpl
then
671 w
.compl_index
= w
.compl_index
+ 1
673 s
.text
= util
.escape(text
)
677 del_word
= function (w
)
678 local i
= w
.ibar
.input
680 local pos
= i
:get_position()
681 if text
and #text
> 1 and pos
> 1 then
682 local left
, right
= string.sub(text
, 2, pos
), string.sub(text
, pos
+1)
683 if not string.find(left
, "%s") then
685 elseif string.find(left
, "%w+%s*$") then
686 left
= string.sub(left
, 0, string.find(left
, "%w+%s*$") - 1)
687 elseif string.find(left
, "%W+%s*$") then
688 left
= string.sub(left
, 0, string.find(left
, "%W+%s*$") - 1)
690 i
.text
= string.sub(text
, 1, 1) .. left
.. right
691 i
:set_position(#left
+ 2)
695 del_line
= function (w
)
696 local i
= w
.ibar
.input
697 if i
.text
~= ":" then
703 -- Search history adding
704 srch_hist_add
= function (w
, srch
)
705 if not w
.srch_hist
then w
.srch_hist
= {} end
707 if #w
.srch_hist
> ((MAX_SRCH_HISTORY
or 100) + 5) then
708 while #w
.srch_hist
> (MAX_SRCH_HISTORY
or 100) do
709 table.remove(w
.srch_hist
, 1)
712 table.insert(w
.srch_hist
, srch
)
715 -- Search history traversing
716 srch_hist_prev
= function (w
)
717 if not w
.srch_hist
then w
.srch_hist
= {} end
718 if not w
.srch_hist_cursor
then
719 w
.srch_hist_cursor
= #w
.srch_hist
+ 1
720 w
.srch_hist_current
= w
.ibar
.input
.text
722 local c
= w
.srch_hist_cursor
- 1
723 if w
.srch_hist
[c
] then
724 w
.srch_hist_cursor
= c
725 w
.ibar
.input
.text
= w
.srch_hist
[c
]
726 w
.ibar
.input
:set_position(-1)
730 srch_hist_next
= function (w
)
731 if not w
.srch_hist
then w
.srch_hist
= {} end
732 local c
= (w
.srch_hist_cursor
or #w
.srch_hist
) + 1
733 if w
.srch_hist
[c
] then
734 w
.srch_hist_cursor
= c
735 w
.ibar
.input
.text
= w
.srch_hist
[c
]
736 w
.ibar
.input
:set_position(-1)
737 elseif w
.srch_hist_current
then
738 w
.srch_hist_cursor
= nil
739 w
.ibar
.input
.text
= w
.srch_hist_current
740 w
.ibar
.input
:set_position(-1)
744 -- Command history adding
745 cmd_hist_add
= function (w
, cmd
)
746 if not w
.cmd_hist
then w
.cmd_hist
= {} end
747 -- Make sure history doesn't overflow
748 if #w
.cmd_hist
> ((MAX_CMD_HISTORY
or 100) + 5) then
749 while #w
.cmd_hist
> (MAX_CMD_HISTORY
or 100) do
750 table.remove(w
.cmd_hist
, 1)
753 table.insert(w
.cmd_hist
, cmd
)
756 -- Command history traversing
757 cmd_hist_prev
= function (w
)
758 if not w
.cmd_hist
then w
.cmd_hist
= {} end
759 if not w
.cmd_hist_cursor
then
760 w
.cmd_hist_cursor
= #w
.cmd_hist
+ 1
761 w
.cmd_hist_current
= w
.ibar
.input
.text
763 local c
= w
.cmd_hist_cursor
- 1
764 if w
.cmd_hist
[c
] then
765 w
.cmd_hist_cursor
= c
766 w
.ibar
.input
.text
= w
.cmd_hist
[c
]
767 w
.ibar
.input
:set_position(-1)
771 cmd_hist_next
= function (w
)
772 if not w
.cmd_hist
then w
.cmd_hist
= {} end
773 local c
= (w
.cmd_hist_cursor
or #w
.cmd_hist
) + 1
774 if w
.cmd_hist
[c
] then
775 w
.cmd_hist_cursor
= c
776 w
.ibar
.input
.text
= w
.cmd_hist
[c
]
777 w
.ibar
.input
:set_position(-1)
778 elseif w
.cmd_hist_current
then
779 w
.cmd_hist_cursor
= nil
780 w
.ibar
.input
.text
= w
.cmd_hist_current
781 w
.ibar
.input
:set_position(-1)
785 -- Searching functions
786 start_search
= function (w
, forward
)
787 -- Clear previous search results
790 local i
= w
.ibar
.input
800 search
= function (w
, text
, forward
)
801 local view
= w
:get_current()
802 local text
= text
or w
.last_search
803 if forward
== nil then forward
= true end
804 local case_sensitive
= false
807 if not text
or #text
== 0 then
813 if w
.searching_forward
== nil then
814 w
.searching_forward
= forward
815 w
.search_start_marker
= view
:get_scroll_vert()
817 -- Invert the direction if originally searching in reverse
818 forward
= (w
.searching_forward
== forward
)
821 view
:search(text
, case_sensitive
, forward
, wrap
);
824 clear_search
= function (w
)
825 w
:get_current():clear_search()
826 -- Clear search state
828 w
.searching_forward
= nil
829 w
.search_start_marker
= nil
832 -- Webview scroll functions
833 scroll_vert
= function(w
, value
, view
)
834 if not view
then view
= w
:get_current() end
835 local cur
, max = view
:get_scroll_vert()
836 if type(value
) == "string" then
837 value
= parse_scroll(cur
, max, value
)
839 view
:set_scroll_vert(value
)
842 scroll_horiz
= function(w
, value
)
843 if not view
then view
= w
:get_current() end
844 local cur
, max = view
:get_scroll_horiz()
845 if type(value
) == "string" then
846 value
= parse_scroll(cur
, max, value
)
848 view
:set_scroll_horiz(value
)
851 -- Tab traversing functions
852 next_tab
= function (w
, n
)
853 w
.tabs
:switch((((n
or 1) + w
.tabs
:current() -1) % w
.tabs
:count()) + 1)
855 prev_tab
= function (w
, n
)
856 w
.tabs
:switch(((w
.tabs
:current() - (n
or 1) -1) % w
.tabs
:count()) + 1)
858 goto_tab
= function (w
, n
)
862 -- History traversing functions
863 back
= function (w
, n
, view
)
864 (view
or w
:get_current()):go_back(n
or 1)
866 forward
= function (w
, n
, view
)
867 (view
or w
:get_current()):go_forward(n
or 1)
870 -- GUI content update functions
871 update_tab_count
= function (w
, i
, t
)
872 w
.sbar
.r
.tabi
.text
= string.format("[%d/%d]", i
or w
.tabs
:current(), t
or w
.tabs
:count())
875 update_win_title
= function (w
, view
)
876 if not view
then view
= w
:get_current() end
877 local title
= view
:get_prop("title")
879 if not title
and not uri
then
880 w
.win
.title
= "luakit"
882 w
.win
.title
= (title
or "luakit") .. " - " .. (uri
or "about:blank")
886 update_uri
= function (w
, view
, uri
)
887 if not view
then view
= w
:get_current() end
888 w
.sbar
.l
.uri
.text
= util
.escape((uri
or (view
and view
.uri
) or "about:blank"))
891 update_progress
= function (w
, view
, p
)
892 if not view
then view
= w
:get_current() end
893 if not p
then p
= view
:get_prop("progress") end
894 if not view
:loading() or p
== 1 then
895 w
.sbar
.l
.loaded
:hide()
897 w
.sbar
.l
.loaded
:show()
898 w
.sbar
.l
.loaded
.text
= string.format("(%d%%)", p
* 100)
902 update_scroll
= function (w
, view
)
903 if not view
then view
= w
:get_current() end
904 local val
, max = view
:get_scroll_vert()
905 if max == 0 then val
= "All"
906 elseif val
== 0 then val
= "Top"
907 elseif val
== max then val
= "Bot"
908 else val
= string.format("%2d%%", (val
/max) * 100)
910 w
.sbar
.r
.scroll
.text
= val
913 update_buf
= function (w
)
915 w
.sbar
.r
.buf
.text
= util
.escape(string.format(" %-3s", w
.buffer
))
922 update_binds
= function (w
, mode
)
923 -- Generate the list of active key & buffer binds for this mode
924 w
.binds
= util
.table.join(mode_binds
[mode
], mode_binds
.all
)
925 -- Clear & hide buffer
930 -- Tab label functions
931 make_tab_label
= function (w
, pos
)
938 t
.label
.font
= theme
.tablabel_font
or theme
.font
939 t
.layout
:pack_start(t
.label
, true, true, 0)
940 t
.layout
:pack_start(t
.sep
, false, false, 0)
941 t
.ebox
:set_child(t
.layout
)
942 t
.ebox
:add_signal("button-press", function (e
, m
, b
)
951 destroy_tab_label
= function (w
, t
)
952 if not t
then t
= table.remove(w
.tbar
.titles
) end
953 for _
, wi
in pairs(t
) do
958 update_tab_labels
= function (w
, current
)
960 local count
, current
= w
.tabs
:count(), current
or w
.tabs
:current()
963 -- Leave the tablist hidden if there is only one tab open
968 if count
~= #tb
.titles
then
969 -- Grow the number of labels
970 while count
> #tb
.titles
do
971 local t
= w
:make_tab_label(#tb
.titles
+ 1)
972 tb
.layout
:pack_start(t
.ebox
, true, true, 0)
973 table.insert(tb
.titles
, t
)
975 -- Prune number of labels
976 while count
< #tb
.titles
do
977 w
:destroy_tab_label()
983 local t
= tb
.titles
[i
]
984 local title
= " " ..i
.. " "..w
:get_tab_title(w
.tabs
:atindex(i
))
985 t
.label
.text
= util
.escape(string.format(theme
.tablabel_format
or "%s", title
))
986 w
:apply_tablabel_theme(t
, i
== current
)
993 apply_tablabel_theme
= function (w
, t
, selected
, atheme
)
994 local theme
= atheme
or theme
996 t
.label
.fg
= theme
.selected_tablabel_fg
or theme
.tablabel_fg
or theme
.fg
997 t
.ebox
.bg
= theme
.selected_tablabel_bg
or theme
.tablabel_bg
or theme
.bg
999 t
.label
.fg
= theme
.tablabel_fg
or theme
.fg
1000 t
.ebox
.bg
= theme
.tablabel_bg
or theme
.bg
1004 apply_window_theme
= function (w
, atheme
)
1005 local theme
= atheme
or theme
1006 local s
, i
, t
= w
.sbar
, w
.ibar
, w
.tbar
1007 local fg
, bg
, font
= theme
.fg
, theme
.bg
, theme
.font
1010 for wi
, v
in pairs({
1011 [s
.l
.uri
] = theme
.uri_fg
or theme
.statusbar_fg
or fg
,
1012 [s
.l
.loaded
] = theme
.loaded_fg
or theme
.statusbar_fg
or fg
,
1013 [s
.r
.buf
] = theme
.buf_fg
or theme
.statusbar_fg
or fg
,
1014 [s
.r
.tabi
] = theme
.tabi_fg
or theme
.statusbar_fg
or fg
,
1015 [s
.r
.scroll
] = theme
.scroll_fg
or theme
.statusbar_fg
or fg
,
1016 [i
.prompt
] = theme
.prompt_fg
or theme
.inputbar_fg
or fg
,
1017 [i
.input
] = theme
.input_fg
or theme
.inputbar_fg
or fg
,
1021 for wi
, v
in pairs({
1022 [s
.l
.ebox
] = theme
.statusbar_bg
or bg
,
1023 [s
.r
.ebox
] = theme
.statusbar_bg
or bg
,
1024 [s
.ebox
] = theme
.statusbar_bg
or bg
,
1025 [i
.ebox
] = theme
.inputbar_bg
or bg
,
1026 [i
.input
] = theme
.input_bg
or theme
.inputbar_bg
or bg
,
1030 for wi
, v
in pairs({
1031 [s
.l
.uri
] = theme
.uri_font
or theme
.statusbar_font
or font
,
1032 [s
.l
.loaded
] = theme
.loaded_font
or theme
.statusbar_font
or font
,
1033 [s
.r
.buf
] = theme
.buf_font
or theme
.statusbar_font
or font
,
1034 [s
.r
.tabi
] = theme
.tabi_font
or theme
.statusbar_font
or font
,
1035 [s
.r
.scroll
] = theme
.scroll_font
or theme
.statusbar_font
or font
,
1036 [i
.prompt
] = theme
.prompt_font
or theme
.inputbar_font
or font
,
1037 [i
.input
] = theme
.input_font
or theme
.inputbar_font
or font
,
1038 }) do wi
.font
= v
end
1042 -- Create new window
1043 function new_window(uris
)
1044 local w
= build_window()
1046 -- Pack the window table full of the common helper functions
1047 for k
, v
in pairs(window_helpers
) do w
[k
] = v
end
1049 attach_window_signals(w
)
1051 -- Apply window theme
1052 w
:apply_window_theme()
1054 -- Populate notebook with tabs
1055 for _
, uri
in ipairs(uris
or {}) do
1059 -- Make sure something is loaded
1060 if w
.tabs
:count() == 0 then
1072 -- vim: ft=lua:et:sw=4:ts=8:sts=4:tw=80