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.
- #drawmessage ⇒ Object
- #drawview ⇒ Object
-
#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.
- #togglestatusline ⇒ Object
Methods included from Util
decode_object, encode_object, error_message, format_duration, format_progress, format_size, parse_format, readline
Constructor Details
#initialize ⇒ Object
initializes a new Aniview application
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 |
# File 'lib/application.rb', line 43 def initialize @term = Util::Term.new @pref = Interface::Pref.new @logger = Logger.new(@pref.parseDir(@pref.get("log_file"))) @logger.level = Logger::DEBUG @pref.logger = @logger @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 @subscription = Interface::Subscription.new @pref, @schedule, @delugec, @c if not @c.server? process = fork do require_relative 'daemon' avd = Daemon.new([]) avd.run end Process.detach(process) end @aiomenu = View::AioMenu.new( interface: @aio, name: @pref.get("menu_titles")["unwatched"], pref: @pref, format: "format_library_unwatched", term: @term, refresh_function: :unwatched, logger: @logger ) @prefmenu = View::PrefMenu.new( interface: @pref, name: @pref.get("menu_titles")["preferences"], pref: @pref, format: "format_preferences", term: @term, children: false, logger: @logger ) @delugemenu = View::DelugeMenu.new( interface: @delugec, name: @pref.get("menu_titles")["torrents"], pref: @pref, format: "format_torrents", term: @term, children: false, logger: @logger ) @schedulemenu = View::ScheduleMenu.new( interface: @schedule, name: @pref.get("menu_titles")["schedule"], pref: @pref, format: "format_schedule", term: @term, children: false, logger: @logger ) @subscriptionmenu = View::SubscriptionMenu.new( interface: @subscription, name: @pref.get("menu_titles")["subscriptions"], pref: @pref, format: "format_subscriptions", term: @term, children: false, logger: @logger ) @term.save.hide_cursor.echo_off end |
Instance Method Details
#changeView(newView) ⇒ Object
Changes the current view in the app
175 176 177 178 179 180 181 182 183 |
# File 'lib/application.rb', line 175 def changeView newView @view.delete_observers @view.pause newView.unpause newView.add_observer(self, :drawview) newView.change_screen_size redraw: false newView. -1 @view = newView end |
#cleanup ⇒ Object
Cleans up Aniview, restoring terminal settings and safely exiting all loops
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/application.rb', line 130 def cleanup @view.pause @statusthread.exit if @statusthread @mthread.exit if @mthread != nil @statusthread.exit if @statusthread != nil @term.reset @mpvbridge.quit! @aio.cleanup exit end |
#drawmessage ⇒ Object
206 207 208 209 210 211 212 213 214 |
# File 'lib/application.rb', line 206 def unless @statusthread @view.draw Thread.new do @statusline.draw @statusline.draw end end end |
#drawview ⇒ Object
185 186 187 188 189 |
# File 'lib/application.rb', line 185 def drawview @view.draw @rcount ||= 0 #puts "refreshed view #{@rcount+=1}" end |
#run ⇒ Object
Runs the aniview application, this method starts all of the threads
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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/application.rb', line 220 def run @view = @aiomenu @view.add_observer(self, :drawview) @statusline.draw @mpvbridge.add_observer(self, :togglestatusline) @statusline.add_observer(self, :drawmessage) mutex = Mutex.new Signal.trap('SIGWINCH', proc { Thread.new { mutex.synchronize { @view.change_screen_size @statusline.draw } } } ) key = "" @view.refresh 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(:unwatched) when kb["goto_library"] changeView @aiomenu @view.setName nm["library"] @view.setFormat("format_library") @view.setRfunc(:items) 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 ":" @view.pause if @statusthread togglestatusline toggled = true end runCommand Util.readline(@term, ":") togglestatusline if toggled @view.unpause when "q" cleanup end @view.control(key) end end |
#runCommand(cmds) ⇒ Object
Executes an Aniview command
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 147 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 @statusline. "unknown command" end end |
#togglestatusline ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/application.rb', line 191 def togglestatusline return unless @mpvbridge.what_changed == "playing_status" unless @statusthread @statusthread = Thread.new do while true @statusline.draw sleep 0.07 end end else @statusthread.exit @statusthread = nil end end |