diff --git a/setup.sh b/setup.sh index 0766ce7..1292b7a 100644 --- a/setup.sh +++ b/setup.sh @@ -7,7 +7,7 @@ set -euo pipefail # - Installs dependencies # - Prompts for API credentials # - Generates .env -# - Starts the bot +# - Prepares to start the bot (does not auto-run) main() { require_unix @@ -19,9 +19,14 @@ main() { prompt_env write_env echo - echo "✅ Setup complete. Starting ritmex-bot..." + # Ensure we end inside the project directory + cd "$PROJECT_DIR" + echo "✅ 安装完成!已进入项目目录:$PROJECT_DIR" + echo "请在终端中输入以下命令启动:" echo - start_bot + echo " bun start" + echo + echo "提示:启动前可检查或编辑当前目录下的 .env 文件。" } require_unix() { @@ -149,12 +154,6 @@ EOF echo "✔ .env created at $(pwd)/${env_file}" } -start_bot() { - # Bun auto-loads .env; no need to run dotenv explicitly - # Ensure Bun has a TTY for interactive menu input - exec bun index.ts < /dev/tty -} - main "$@" diff --git a/src/ui/App.tsx b/src/ui/App.tsx index c2b76e2..b0cd784 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { Box, Text, useInput, useStdin } from "ink"; +import { Box, Text, useInput } from "ink"; import { TrendApp } from "./TrendApp"; import { MakerApp } from "./MakerApp"; import { OffsetMakerApp } from "./OffsetMakerApp"; @@ -32,15 +32,9 @@ const STRATEGIES: StrategyOption[] = [ }, ]; -// Prefer Ink's stdin detection to avoid false negatives when spawned by shells -// that don't propagate process.stdin TTY flags correctly. -function useInputSupported() { - const { isRawModeSupported } = useStdin(); - return Boolean(isRawModeSupported); -} +const inputSupported = Boolean(process.stdin && (process.stdin as any).isTTY); export function App() { - const inputSupported = useInputSupported(); const [cursor, setCursor] = useState(0); const [selected, setSelected] = useState(null); diff --git a/src/ui/MakerApp.tsx b/src/ui/MakerApp.tsx index 85be540..4c1a88d 100644 --- a/src/ui/MakerApp.tsx +++ b/src/ui/MakerApp.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; -import { Box, Text, useInput, useStdin } from "ink"; +import { Box, Text, useInput } from "ink"; import { makerConfig } from "../config"; import { AsterExchangeAdapter } from "../exchanges/aster-adapter"; import { MakerEngine, type MakerEngineSnapshot } from "../core/maker-engine"; @@ -10,13 +10,9 @@ interface MakerAppProps { onExit: () => void; } -function useInputSupported() { - const { isRawModeSupported } = useStdin(); - return Boolean(isRawModeSupported); -} +const inputSupported = Boolean(process.stdin && (process.stdin as any).isTTY); export function MakerApp({ onExit }: MakerAppProps) { - const inputSupported = useInputSupported(); const [snapshot, setSnapshot] = useState(null); const [error, setError] = useState(null); const engineRef = useRef(null); diff --git a/src/ui/OffsetMakerApp.tsx b/src/ui/OffsetMakerApp.tsx index df8405f..bd9a1d9 100644 --- a/src/ui/OffsetMakerApp.tsx +++ b/src/ui/OffsetMakerApp.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; -import { Box, Text, useInput, useStdin } from "ink"; +import { Box, Text, useInput } from "ink"; import { makerConfig } from "../config"; import { AsterExchangeAdapter } from "../exchanges/aster-adapter"; import { OffsetMakerEngine, type OffsetMakerEngineSnapshot } from "../core/offset-maker-engine"; @@ -10,13 +10,9 @@ interface OffsetMakerAppProps { onExit: () => void; } -function useInputSupported() { - const { isRawModeSupported } = useStdin(); - return Boolean(isRawModeSupported); -} +const inputSupported = Boolean(process.stdin && (process.stdin as any).isTTY); export function OffsetMakerApp({ onExit }: OffsetMakerAppProps) { - const inputSupported = useInputSupported(); const [snapshot, setSnapshot] = useState(null); const [error, setError] = useState(null); const engineRef = useRef(null); diff --git a/src/ui/TrendApp.tsx b/src/ui/TrendApp.tsx index 8301d09..6eef9a2 100644 --- a/src/ui/TrendApp.tsx +++ b/src/ui/TrendApp.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; -import { Box, Text, useInput, useStdin } from "ink"; +import { Box, Text, useInput } from "ink"; import { tradingConfig } from "../config"; import { AsterExchangeAdapter } from "../exchanges/aster-adapter"; import { TrendEngine, type TrendEngineSnapshot } from "../core/trend-engine"; @@ -12,13 +12,9 @@ interface TrendAppProps { onExit: () => void; } -function useInputSupported() { - const { isRawModeSupported } = useStdin(); - return Boolean(isRawModeSupported); -} +const inputSupported = Boolean(process.stdin && (process.stdin as any).isTTY); export function TrendApp({ onExit }: TrendAppProps) { - const inputSupported = useInputSupported(); const [snapshot, setSnapshot] = useState(null); const [error, setError] = useState(null); const engineRef = useRef(null);