What is the logic underlying this proof? Proposition: A metric space $X$ is connected if, and only if, every continuous function $f:X\to (\{0,1\},d_D)$ is a constant function, where $d_D$ is the discrete metric on the set $\{0,1\}$.
  
  Proof: Suppose $X$ is disconnected. Then $X$ has a nonempty proper subset $A$ which is both open and closed. Define the function $f:X\to (\{0,1\},d_D)$ by $$f(x)=\left\{\begin{array}
&amp;0 &amp; \text{if } x\in A\\
1 &amp; \text{if } x\notin A \end{array} \right.$$ There are only four open sets in $\{0,1\}$, and it is easy to check that the inverse image of each one of them under the function $f$ is an open set in $X$. Hence $f$ is continuous, and clearly not constant.
  
  Conversely, suppose there is a continuous function $f:X\to (\{0,1\},d_D)$ which is not constant....


Can you please explain the logic behind the first part of the proof given above? This is my attempt to understand the logic:

Let the statement "every continuous function $f:X\to (\{0,1\},d_D)$ is a constant function" be denoted $A$; and the statement "$X$ is connected" be denoted $B$. The first part of the proof has proved that $A\wedge\neg B$ is false when $B$ is false. Hence $A$ is false (I'm not sure if this is relevant, but it does mean that $A\implies B$ is true, because $A$ is false).

If the author is trying to prove the contrapositive, I think that he failed because he did not prove $\neg B \implies \neg A$ for all cases of non-constant continuous functions, just one. What I usually expect is a proof by contradiction. If this were a proof by contradiction, what is being implied at the start are the words, "Suppose $X$ is disconnected and suppose every continuous function $f:X\to (\{0,1\},d_D)$ is constant." Why would a contradiction then lead to the conclusion that $X$ must have been connected? Why do we not simply conclude that there exists a non-constant function $f:X\to (\{0,1\},d_D)$ when $X$ is disconnected? What is so special about the statement $A$ that it must be possible to be true under one of the conditions '$X$ is connected' or '$X$ is disconnected'?
The author proves $\neg B \implies \neg A$, so $A\implies B$.

Indeed $\neg A$ reads "there is a continuous non-constant function $X\to \{0;1\}$", which is what the author proves.
The proposition is $B\iff A$. The first part of th eprove starts with "Suppose $\neg A$" and deduces $\neg B$ from that, thus shows $\neg A\implies \neg B$ (or equivalently $B\implies A$)