UNPKG

portio

Version:

A beautiful terminal UI for managing processes on network ports (Windows only)

51 lines (50 loc) 1.72 kB
import React, { useEffect, useState } from 'react'; import { Box, Text, useApp } from 'ink'; import { getProcessOnPort } from '../utils/portDetector.js'; export const CheckMode = ({ port }) => { const { exit } = useApp(); const [loading, setLoading] = useState(true); const [process, setProcess] = useState(null); const [error, setError] = useState(null); useEffect(() => { const checkPort = async () => { try { const proc = await getProcessOnPort(port); setProcess(proc); } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error'); } finally { setLoading(false); setTimeout(() => exit(), 100); } }; checkPort(); }, [port, exit]); if (loading) { return (React.createElement(Text, { color: "yellow" }, "Checking port ", port, "...")); } if (error) { return (React.createElement(Box, { flexDirection: "column" }, React.createElement(Text, { color: "red" }, "Error: ", error))); } if (!process) { return (React.createElement(Text, { color: "green" }, "\u2713 Port ", port, " is free")); } return (React.createElement(Box, { flexDirection: "column" }, React.createElement(Text, null, process.processName || 'Unknown', " (PID: ", process.pid, ")"), process.command && process.command !== 'N/A' && (React.createElement(Text, { dimColor: true }, process.command)))); };