Move terminal-related selection logic into st.c