Class: Aniview::Application
Overview
Main class for the aniview application
Instance Method Summary collapse
-
#change_view(view:, rfunc: :items, format: nil, name: nil) ⇒ 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, mounted_filesystem?, 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 |
# 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")["library"], pref: @pref, format: "format_library", term: @term, 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
#change_view(view:, rfunc: :items, format: nil, name: nil) ⇒ Object
Changes the current view in the app
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/application.rb', line 174 def change_view(view:, rfunc: :items, format:nil, name:nil) @view.delete_observers @view.pause view.attributes["t"] = name if name view.format = format if format view.rfunc = rfunc view.add_observer(self, :drawview) view.change_screen_size redraw: false view. -1 view.unpause @view = view end |
#cleanup ⇒ Object
Cleans up Aniview, restoring terminal settings and safely exiting all loops
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/application.rb', line 129 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
210 211 212 213 214 215 216 217 218 |
# File 'lib/application.rb', line 210 def unless @statusthread @view.draw Thread.new do @statusline.draw @statusline.draw end end end |
#drawview ⇒ Object
187 188 189 190 191 192 |
# File 'lib/application.rb', line 187 def drawview @view.draw #@statusline.draw @rcount ||= 0 #puts "refreshed view #{@rcount+=1}" end |
#run ⇒ Object
Runs the aniview application, this method starts all of the threads
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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/application.rb', line 224 def run @logger.debug "yo" nm = @pref.get("menu_titles") views = { :unwatched => {view: @aiomenu, name: nm["unwatched"], format: "format_library_unwatched", rfunc: :unwatched}, :library => {view: @aiomenu, name: nm["library"], format: "format_library"}, :torrents => {view: @delugemenu}, :preferences => {view: @prefmenu}, :schedule => {view: @schedulemenu}, :subscription => {view: @subscriptionmenu} } current_view = 0 @view = @aiomenu @view.add_observer(self, :drawview) @mpvbridge.add_observer(self, :togglestatusline) @statusline.add_observer(self, :drawmessage) @statusline.draw 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") case key when kb["goto_unwatched"] change_view(views[:unwatched]) current_view = 0 when kb["goto_library"] change_view(views[:library]) current_view = 1 when kb["goto_torrents"] change_view(views[:torrents]) current_view = 2 when kb["goto_preferences"] change_view(views[:preferences ]) current_view = 5 when kb["goto_schedule"] change_view(views[:schedule]) current_view = 3 when kb["goto_subscriptions"] change_view(views[:subscription]) current_view = 4 when "right" current_view += 1 current_view = views.length - 1 if current_view >= views.length change_view(views.values[current_view]) when "left" current_view -= 1 current_view = 0 if current_view < 0 change_view(views.values[current_view]) 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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# 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 @statusline. "unknown command" end end |
#togglestatusline ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/application.rb', line 194 def togglestatusline @logger.debug "toggling status line" return unless @mpvbridge.what_changed.key? :playing_status unless @statusthread @statusthread = Thread.new do while true @statusline.draw sleep 0.07 end end else @statusthread.exit @statusthread = nil end end |