Class: Aniview::Application
Overview
Main class for the aniview application
Instance Method Summary collapse
-
#changeView(newView) ⇒ Object
Changes the current view in the app.
-
#cleanup ⇒ Object
Cleans up Aniview, restoring terminal settings and safely exiting all loops.
-
#initialize ⇒ Object
constructor
initializes a new Aniview application.
-
#run ⇒ Object
Runs the aniview application, this method starts all of the threads.
-
#runCommand(cmds) ⇒ Object
Executes an Aniview command.
Methods included from Util
decode_object, encode_object, format_duration, format_progress, format_size, parse_format, readline
Constructor Details
#initialize ⇒ Object
initializes a new Aniview application
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/application.rb', line 39 def initialize @term = Util::Term.new @pref = Interface::Pref.new @mpvbridge = Interface::MPVBridge.new @pref @aio = Interface::AnimeIO.new @pref, @mpvbridge @schedule = Interface::Schedule.new @pref @delugec = Interface::DelugeC.new @pref @c = Client::AniClient.new @pref @statusline = View::StatusLine.new @pref, @term, @mpvbridge #file = "/Users/lattis/anime/Tekkonkinkreet/Tekkonkinkreet.mkv" #@mpvbridge.play file #while true # @statusline.draw # sleep 1/45.0 #end @subscription = Interface::Subscription.new(@pref, @schedule, @delugec, @c) if not @c.server? #puts "starting server" process = fork do require_relative 'daemon' avd = Daemon.new([]) avd.run end Process.detach(process) end @aiomenu = View::AioMenu.new( refresh_function: :getUnwatched, interface: @aio, name: @pref.get("menu_titles")["unwatched"], pref: @pref, format: "format_library_unwatched", term: @term ) @prefmenu = View::PrefMenu.new( refresh_function: :getAll, interface: @pref, name: @pref.get("menu_titles")["preferences"], pref: @pref, format: "format_preferences", term: @term, children: false ) @delugemenu = View::DelugeMenu.new( refresh_function: :getTorrents, interface: @delugec, name: @pref.get("menu_titles")["torrents"], pref: @pref, format: "format_torrents", term: @term, children: false ) @schedulemenu = View::ScheduleMenu.new( refresh_function: :getAll, interface: @schedule, name: @pref.get("menu_titles")["schedlue"], pref: @pref, format: "format_schedule", term: @term, children: false ) @subscriptionmenu = View::SubscriptionMenu.new( refresh_function: :getAll, interface: @subscription, name: @pref.get("menu_titles")["subscriptions"], pref: @pref, format: "format_subscriptions", term: @term, children: false ) @term.save.hide_cursor.echo_off end |
Instance Method Details
#changeView(newView) ⇒ Object
Changes the current view in the app
175 176 177 178 |
# File 'lib/application.rb', line 175 def changeView newView @view = newView @view.change_screen_size end |
#cleanup ⇒ Object
Cleans up Aniview, restoring terminal settings and safely exiting all loops
132 133 134 135 136 137 138 |
# File 'lib/application.rb', line 132 def cleanup @mthread.exit if @mthread != nil @statusthread.exit if @statusthread != nil @term.reset @mpvbridge.quit! exit end |
#run ⇒ Object
Runs the aniview application, this method starts all of the threads
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/application.rb', line 185 def run @view = @aiomenu mutex = Mutex.new Signal.trap('SIGWINCH', proc { Thread.new { mutex.synchronize { @view.change_screen_size } } } ) key = "" @view.refresh @shoulddraw = true Thread.abort_on_exception = true @mthread = Thread.new do while true if @shoulddraw @view.draw @view.refresh end sleep 1/45.0 end end @statusthread = Thread.new do while true if @shoulddraw @statusline.draw end sleep 1/25.0 end end while true @shoulddraw = true key = @term.getKey @shoulddraw = false kb = @pref.get("keybindings") nm = @pref.get("menu_titles") case key when kb["goto_unwatched"] changeView @aiomenu @view.setName nm["unwatched"] @view.setFormat("format_library_unwatched") @view.setRfunc(:getUnwatched) when kb["goto_library"] changeView @aiomenu @view.setName nm["library"] @view.setFormat("format_library") @view.setRfunc(:getAll) when kb["goto_torrents"] changeView @delugemenu @view.setName nm["torrents"] when kb["goto_preferences"] changeView @prefmenu @view.setName nm["preferences"] when kb["goto_schedule"] changeView @schedulemenu @view.setName nm["schedule"] when kb["goto_subscriptions"] changeView @subscriptionmenu @view.setName nm["subscriptions"] when ":" runCommand Util.readline(@term, ":") when "q" cleanup end @view.control(key) end end |
#runCommand(cmds) ⇒ Object
Executes an Aniview command
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/application.rb', line 146 def runCommand(cmds) cmd_s = cmds.split cmd = cmd_s[0] if cmd == "quit" self.cleanup elsif cmd == "sync" #alist = Anilist.new #alist.sync elsif cmd == "pref" @pref.set cmd_s[1], cmd_s[2] elsif cmd == "index" @aio.index_anime :force => true, :verbose => true @aiomenu.refresh elsif cmd == "help" print "\e[1;1H" + Aniview::View::Color.white puts "Help" puts "" else print "\033[" + String(@term.rows) + ";1H" + Aniview::View::Color.red + "error, unknown command" @term.getKey end end |