How can I write a command that does the following?

  - With a mapping, compile and/or run a program based on the filetype (`*.c`,
      `*.cpp`, `*.js`, `*.py`, etc.), and open a vertical terminal window with
      the output.
  - With *another* mapping, close the vertical terminal window.
    
I know you can open the terminal next to Vim with `tmux`, but I want to do it
with just Vim.