teditor  1.8.0@@fee5e94
Terminal based editor written in C++
extensions/watch/mode.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../base/readonly.h"
4 #include "core/buffer.h"
5 #include <atomic>
6 #include <memory>
7 #include <thread>
8 
9 namespace teditor {
10 namespace watch {
11 
14  public:
15  WatchMode();
16  ~WatchMode() { stop(); }
17 
18  Strings cmdNames() const;
19 
20  static Mode* create() { return new WatchMode; }
21  static bool modeCheck(const std::string& file) { return file == "*watch"; }
22 
23  void start(Buffer* buf, const std::string& cmd,
24  int sleepLenMs = 0);
25  void stop();
26  void restart() { stop(); start(); }
27 
28  int sleepTimeMs() const { return sleepMilliSec; }
29 
30  private:
31  struct Keys { static std::vector<KeyCmdPair> All; };
32  struct Colors { static std::vector<NameColorPair> All; };
33 
34  Buffer* buf; // NOT owned by this class
35  std::string watchCmd;
36  int defaultSleepMilliSec;
37  int sleepMilliSec;
38  std::atomic<bool> alreadyRunning;
39  std::shared_ptr<std::thread> runner;
40 
41  void start();
42  void writeOutput();
43 }; // class WatchMode
44 
45 } // namespace watch
46 } // namespace teditor
teditor::watch::WatchMode::cmdNames
Strings cmdNames() const
Definition: extensions/watch/mode.cpp:17
teditor::watch::WatchMode
Definition: extensions/watch/mode.h:13
teditor::Strings
std::vector< std::string > Strings
Definition: utils.h:42
teditor::watch::WatchMode::modeCheck
static bool modeCheck(const std::string &file)
Definition: extensions/watch/mode.h:21
teditor::watch::WatchMode::restart
void restart()
Definition: extensions/watch/mode.h:26
teditor::watch::WatchMode::start
void start(Buffer *buf, const std::string &cmd, int sleepLenMs=0)
Definition: extensions/watch/mode.cpp:35
buffer.h
teditor::Mode
Definition: core/mode.h:27
teditor::watch::WatchMode::~WatchMode
~WatchMode()
Definition: extensions/watch/mode.h:16
teditor::watch::WatchMode::sleepTimeMs
int sleepTimeMs() const
Definition: extensions/watch/mode.h:28
teditor::watch::WatchMode::stop
void stop()
Definition: extensions/watch/mode.cpp:44
teditor::watch::WatchMode::create
static Mode * create()
Definition: extensions/watch/mode.h:20
teditor::Buffer
Definition: buffer.h:25
teditor
Definition: any.hpp:10
teditor::readonly::ReadOnlyMode
Definition: readonly.h:11
teditor::watch::WatchMode::WatchMode
WatchMode()
Definition: extensions/watch/mode.cpp:9