Move terminal cleanup to Drop implementation

[?]
Jan 17, 2022, 7:33 PM
272LZTVTE66SQ4BYDORDIBSQFKG3357ZYIUNPVOGUC47VFXOAKVQC

Dependencies

  • [2] QEKHTVB7 Get most things semi-working except the final sort
  • [3] LPVC545K Get the scraper part of this program working
  • [4] 5Y7ZXB53 Start picker UI
  • [5] CYDK6S5L Fix bugs
  • [6] G5YNDTPH Cargo clippy
  • [7] KUANIPWF Add function for adding name to database
  • [8] RNW6D777 Minor tidy
  • [9] YCWYAX6K Functions for scraping names integrated enough to test (they don't work yet)
  • [10] LLFG625I Should be all the database functions I need
  • [11] AV73DYWQ Initial functions for using sqlite in async environment
  • [12] HMOBTVJ4 Initialize crate and add expected dependencies

Change contents

  • replacement in src/pick.rs at line 10
    [3.163][2.115:155]()
    use futures::stream::{self, StreamExt};
    [3.163]
    [2.155]
    use futures::stream::StreamExt;
  • replacement in src/pick.rs at line 65
    [3.153][3.153:188](),[3.188][2.1657:1875]()
    stderr.execute(cursor::Hide)?;
    terminal::enable_raw_mode()?;
    let (mut input, _done) = events();
    let mut comparator = CompareContext {
    db,
    events: &mut input,
    out: &mut stderr,
    needs_newline: false,
    };
    [3.153]
    [2.1875]
    let mut comparator = CompareContext::new(&db, &mut stderr)?;
  • edit in src/pick.rs at line 106
    [2.2736][3.227:262](),[3.227][3.227:262](),[3.262][2.2737:2772]()
    stderr.execute(cursor::Show)?;
    terminal::disable_raw_mode()?;
  • replacement in src/pick.rs at line 112
    [2.2776][2.2776:2807]()
    struct CompareContext<'a, W> {
    [2.2776]
    [2.2807]
    struct CompareContext<'a, W: std::io::Write> {
  • replacement in src/pick.rs at line 114
    [2.2836][2.2836:2888]()
    events: &'a mut stream::Abortable<EventStream>,
    [2.2836]
    [2.2888]
    events: EventStream,
  • edit in src/pick.rs at line 117
    [2.2933]
    [3.359]
    }
    impl<'a, W: std::io::Write> std::ops::Drop for CompareContext<'a, W> {
    fn drop(&mut self) {
    self.out.execute(cursor::Show).ok();
    terminal::disable_raw_mode().ok();
    }
  • edit in src/pick.rs at line 127
    [2.2987]
    [2.2987]
    fn new(db: &'a AsyncConnection, out: &'a mut W) -> DynResult<Self> {
    out.execute(cursor::Hide)?;
    terminal::enable_raw_mode()?;
    Ok(Self {
    db,
    events: EventStream::new(),
    out,
    needs_newline: false,
    })
    }
  • edit in src/pick.rs at line 238
    [2.6612][3.362:482](),[3.362][3.362:482]()
    pub fn events() -> (stream::Abortable<EventStream>, stream::AbortHandle) {
    stream::abortable(EventStream::new())
    }
  • replacement in src/main.rs at line 23
    [3.112][2.6750:7082](),[3.168][3.1643:1653](),[3.779][3.1643:1653](),[3.1078][3.1643:1653](),[3.5371][3.1643:1653](),[2.7082][3.1643:1653](),[3.1643][3.1643:1653](),[3.1653][2.7083:7091]()
    match pick::pick(&db, args.count, args.gather).await {
    Ok(r) => Ok(r),
    Err(e) => {
    use crossterm::ExecutableCommand;
    let mut stderr = std::io::stderr();
    stderr.execute(crossterm::cursor::Show).ok();
    crossterm::terminal::disable_raw_mode().ok();
    Err(e)
    }
    }?;
    [3.112]
    [2.7091]
    pick::pick(&db, args.count, args.gather).await?;